Ext-JS 4: Modify the data store of grid & ldquo; Cell-editing & rdquo; Example of using JSON instead of XML


Below is a snippet from the "cell-editing.js" file in the Sencha.com Ext JS 4 example. I'd like to turn this xml data store into a json data store using json.get. And also get an example json file so I can turn that into dynamic json. Note, see the code block under "// create the Data Store". Right now, it's showing an xml format. How can this be done?



(version of 4.1.0 might change in future)

I did a similar thing with their treegrid.js file, but because the structure of the cell-editing example contains multiple field types (string, combobox/select, boolean, etc..), I didn't know what the structure of the json file needed to be. Here is the treegrid.js code:

var store = Ext.create('Ext.data.TreeStore', {
    model: 'Task',
    proxy: {
        type: 'ajax',
        url: 'http://localhost:8888/TreeGrid.ashx'  // OR set to static file 'treegrid.json'
    folderSort: true

"cell-editing.js" file:

    enabled: true
Ext.Loader.setPath('Ext.ux', '../ux');



    function formatDate(value){
        return value ? Ext.Date.dateFormat(value, 'M d, Y') : '';

    Ext.define('Plant', {
        extend: 'Ext.data.Model',
        fields: [
            // the 'name' below matches the tag name to read, except 'availDate'
            // which is mapped to the tag 'availability'
            {name: 'common', type: 'string'},
            {name: 'botanical', type: 'string'},
            {name: 'light'},
            {name: 'price', type: 'float'},
            // dates can be automatically converted by specifying dateFormat
            {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
            {name: 'indoor', type: 'bool'}

    // create the Data Store
    var store = Ext.create('Ext.data.Store', {
        // destroy the store if the grid is destroyed
        autoDestroy: true,
        model: 'Plant',
        proxy: {
            type: 'ajax',
            // load remote data using HTTP
            url: 'plants.xml',
            // specify a XmlReader (coincides with the XML format of the returned data)
            reader: {
                type: 'xml',
                // records will have a 'plant' tag
                record: 'plant'
        sorters: [{
            property: 'common',

    var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
        clicksToEdit: 1

    // create the grid and specify what field you want
    // to use for the editor at each header.
    var grid = Ext.create('Ext.grid.Panel', {
        store: store,
        columns: [{
            id: 'common',
            header: 'Common Name',
            dataIndex: 'common',
            flex: 1,
            editor: {
                allowBlank: false
        }, {
            header: 'Light',
            dataIndex: 'light',
            width: 130,
            editor: {
                xtype: 'combobox',
                typeAhead: true,
                triggerAction: 'all',
                selectOnTab: true,
                store: [
                    ['Mostly Shady','Mostly Shady'],
                    ['Sun or Shade','Sun or Shade'],
                    ['Mostly Sunny','Mostly Sunny'],
                lazyRender: true,
                listClass: 'x-combo-list-small'
        }, {
            header: 'Price',
            dataIndex: 'price',
            width: 70,
            align: 'right',
            renderer: 'usMoney',
            editor: {
                xtype: 'numberfield',
                allowBlank: false,
                minValue: 0,
                maxValue: 100000
        }, {
            header: 'Available',
            dataIndex: 'availDate',
            width: 95,
            renderer: formatDate,
            editor: {
                xtype: 'datefield',
                format: 'm/d/y',
                minValue: '01/01/06',
                disabledDays: [0, 6],
                disabledDaysText: 'Plants are not available on the weekends'
        }, {
            xtype: 'checkcolumn',
            header: 'Indoor?',
            dataIndex: 'indoor',
            width: 55
        selModel: {
            selType: 'cellmodel'
        renderTo: 'editor-grid',
        width: 600,
        height: 300,
        title: 'Edit Plants?',
        frame: true,
        tbar: [{
            text: 'Add Plant',
            handler : function(){
                // Create a model instance
                var r = Ext.create('Plant', {
                    common: 'New Plant 1',
                    light: 'Mostly Shady',
                    price: 0,
                    availDate: Ext.Date.clearTime(new Date()),
                    indoor: false
                store.insert(0, r);
                cellEditing.startEditByPosition({row: 0, column: 0});
        plugins: [cellEditing]

    // manually trigger the data store load
        // store loading is asynchronous, use a load listener or callback to handle results
        callback: function(){
                title: 'Store Load Callback',
                msg: 'store was loaded, data available for processing',
                modal: false,
                icon: Ext.Msg.INFO,
                buttons: Ext.Msg.OK

"plants.xml" file:

<?xml version="1.0" encoding="ISO-8859-1"?>
    <botanical>Sanguinaria canadensis</botanical>
    <light>Mostly Shady</light>
    <botanical>Aquilegia canadensis</botanical>
    <light>Mostly Shady</light>

Change the proxy reader type to "json"