1. #1
    Sencha User
    Join Date
    Jul 2009
    Posts
    135
    Vote Rating
    1
    silve69 is on a distinguished road

      0  

    Default Using CheckboxModel with default checked rows

    Using CheckboxModel with default checked rows


    Hello folks,

    I'm using an Ext.selection.CheckboxModel in a grid, but I don't know how checked some rows by default.
    Code:
    var layers_store = new Ext.data.Store({
        autoLoad: false, 
        proxy: { 
            type: 'ajax', 
            url: 'modules/view.php', 
            reader: { 
                type: 'json', 
                root: 'results', 
                successProperty: 'success' 
            }, 
        },
        fields: [{name:'idlayer',type:'int'}, 'layer', {name:'checked',type:'int'}]
    });
    
    
    ...
    ...
    },{
        xtype: 'grid', 
        store: layers_store, 
        columnLines: true, 
        viewConfig: { stripeRows: true },
        selModel: Ext.create('Ext.selection.CheckboxModel'),
        columns: [{ header: 'Layers', dataIndex: 'layer' }]
    },{
    ...
    Received JSON:
    Code:
    [{"idlayer":"18","layer":"Towns","checked":"1"},{"idlayer":"19","layer":"Rivers","checked":"0"}]
    For treepanel only is necessary a "checked" field, but with the CheckboxModel doesn't works.
    Some suggestion??

    Best regards,
    Silver

  2. #2
    Sencha User
    Join Date
    Jun 2011
    Posts
    55
    Vote Rating
    1
    Gabanjo is on a distinguished road

      1  

    Default


    I don't think you can set it based on a property like you can for TreeStore. (I guess because it represents user selections not features of the data.)

    If that's right you'll have to do it in your code somewhere, maybe like this:

    Code:
       viewConfig: { stripeRows: true,
         listeners : {
              beforerefresh : function(view) {
                     var store = view.getStore();
                     var model = view.getSelectionModel();
                     var s = [];
                     store.queryBy(function(record) {
                           if (record.get('layer') === 'Rivers') {
                                  s.push(record);
                           }
                    });
                    model.select(s);
               },
        }
     },
    It would be a useful feature, so I hope I'm wrong.

  3. #3
    Sencha User
    Join Date
    Apr 2014
    Posts
    15
    Vote Rating
    0
    anant.choubey is on a distinguished road

      0  

    Default Thanks

    Thanks


    Hi Gabanjo

    I was able to fix the same issue with the code you provided.

    Thanks for posting.

Thread Participants: 2