开发者

json to load values into extjs checkboxgroup grid editor

I need to set up a CheckboxGroup checkboxes with values loaded with json from some url. What is a correct format of JSON?

Many thanks for help!

Update: I'll clarify my problem.

I'm using EditorGridPanel. Rows are Periods. There are columns Start_at, Finish_at, Region. First and second are date and everything ok with them. Problem with Region which actually is a CheckboxGroup with a checkbox for each week day - Monday, Tuesday, etc. So:

First I'm loading data from server into store

function setupDataSource() {
    row = Ext.data.Record.create([
        { name: 'start_at', type: 'string' },
        { name: 'finish_at', type: 'string' },
        { name: 'region', type: 'string' }
    ]);      

    store = new Ext.data.Store({
        url: '/country/195/periods',
        reader: new Ext.data.JsonReader(
            {
                root: 'rows',
                id: 'id'
            }, 
            row
        )
    });

    store.load();

}

URL url: '/country/195/periods' returns JSON:

{"rows": [{"region": {"cbvert_1": 1, "cbvert_2": 0, "cbvert_3": 1, "cbvert_4": 0, "cbvert_5": 1, "cbvert_6": 0, "cbvert_7": 1}, "start_at": "2010-10-17", "id": 1, "finish_at": "2010-10-28"}]}

Then I'm building a grid:

function buildGrid() { 

    sm = new Ext.grid.RowSelectionModel();     
    cm = new Ext.grid.ColumnModel([

        // ... Start at and Finish at columns definition here ...

        { header: 'Region',
          dataIndex: 'region', 
            width: 150, 
            editor: new Ext.form.CheckboxGroup({    
            xtype: 'checkboxgroup',
        columns: 7,
        vertical: true,
        items: [
           {boxLabel: 'M', name: 'cbvert_1', inputValue: 1},
           {boxLabel: 'T', name: 'cbvert_2', inputValue: 1},
           {boxLabel: 'W', name: 'cbvert_3', inputValue: 1},
           {boxLabel: 'T', name: 'cbvert_4', inputValue: 1},
           {boxLabel: 'F', name: 'cbvert_5', inputValue: 1},
           {boxLabel: 'S', name: 'cbvert_6', inputValue: 1},
           {boxLabel: 'S', name: 'cbvert_7', inputValue: 1},
                    ]
                }),
            re开发者_如何学Cnderer: function(value) {}
        }]);  

     // ...

}

So, when I'm clicking on a grid cell I need to get checkboxes preselected with values previously stored in database. Now all checkboxes are stay blank but should be 1010101 as its in JSON.

Please point me to errors or maybe a some kind of a solution. Any help will be greatly appreciated. Many thanks!


Check this out: http://www.sencha.com/forum/showthread.php?47243-Load-data-in-checkboxgroup

Updated: Remove the type declaration of the region field. You do not need a string but an object (from JSON). It works just fine that way :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜