extjs - Preselect items in EXT JS 4.2 Grid -
i trying preselect items in ext grid based on value of 1 of items in data store.
in data store fetch 7 items, last item grab 'installed' boolean , use preselect items in grid.
here code have far not working...
ext.require([ 'ext.grid.*', 'ext.data.*', 'ext.selection.checkboxmodel' ]); ext.onready(function(){ ext.quicktips.init(); var sb = $('#sb_id').val(); // data store var data = ext.create('ext.data.jsonstore', { autoload: true, fields: [ 'name', 'market', 'expertise', 'id', 'isfull', 'isprimary', 'installed'], proxy: { type: 'ajax', url: '/opslibrary/getlibraryjsonedit', extraparams: { sb_id: sb }, actionmethods: 'post' }, sorters: [{ property: 'market', direction: 'asc' }, { property: 'expertise', direction: 'asc' }] }); data.on('load',function(records){ ext.each(records,function(record){ var recs = []; ext.each(record, function(item, index){ console.log(item.data); if (item.data['installed'] == true) { console.log('hi!'); recs.push(index); } }); //data.getselectionmodel().selectrows(recs); }) }); // selection model var selmodel = ext.create('ext.selection.checkboxmodel', { columns: [ {xtype : 'checkcolumn', text : 'active', dataindex : 'id'} ], listeners: { selectionchange: function(value, meta, record, row, rowindex, colindex){ var selectedrecords = grid4.getselectionmodel().getselection(); var selectedparams = []; // clear input , reset vars $('#selected-libraries').empty(); var record = null; var isfull = null; var isprimary = null; // loop through selected records for(var = 0, len = selectedrecords.length; < len; i++){ record = selectedrecords[i]; // full library checked? isfull = record.get('isfull'); // primary library? isprimary = record.get('isprimary'); // build data object selectedparams.push({ id: record.getid(), full: isfull, primary: isprimary }); } // json encode object , set hidden input $('#selected-libraries').val(json.stringify(selectedparams)); }} });
i trying use on.load method once store populated go , preselect items not having luck.
im python guy , don't around js sorry noobness.
any appreciated.
thanks again!
you should able like:
//create selmodel instance above data.on('load', function(st, recs) { var installedrecords = ext.array.filter(recs, function(rec) { return rec.get('installed'); }); //selmodel instance selmodel.select(installedrecords); });
select can take array of records.
http://docs.sencha.com/extjs/4.2.1/#!/api/ext.selection.model-method-select
//data.getselectionmodel().selectrows(recs);
didn't work because store's don't have reference selection models other way around. can selection model grid doing grid.getselectionmodel() or can use selmodel instance created
var selmodel = ext.create('ext.selection.checkboxmodel', {
Comments
Post a Comment