1,返回的n条数据中的m条数据设置了被选中,想在初始化的时候让这一行数据被选中;
2,效果图如下
3,测试数据
[ { 'name':'张三', price:'100块', change:'no', code:'1' }, { 'name':'李四', price:'1000块', change:'yes', code:'1' }, { 'name':'王五', price:'10000块', change:'yes', code:'0' } ]4,主要代码
Ext.define('app.view.common.RowChangeBgColor', { extend: 'Ext.grid.Panel', xtype: 'row-change-bg-grid', reference: 'RowChangeBgColor', id: 'RowChangeBgColor', title: 'change Grid', viewModel: { data: { code: [] } }, buttons: [ { text: '选中', handler: function () { this.up('grid').getSelectionModel().select(0, true) } } ], selModel: { type: 'checkboxmodel', checkOnly: true }, viewConfig: { stripeRows: true, forceFit: true, scrollOffset: 0, enableTextSelection: true, expandOnly: true, listeners: { beforerender: function (grid, eOpts) { grid.ownerGrid.store.on("load", function () { var codearr = grid.ownerGrid.viewModel.get('code'); if (codearr.length) { for (var i = 0, len = codearr.length; i < len; i++) { var index = parseInt(codearr[i]); if (index >= 0) { grid.ownerGrid.getSelectionModel().select(index, true); } } } codearr = []; }); grid.ownerGrid.getStore().load(); }, selectionchange: function (grid, record, eOpts) { } }, getRowClass: function (record, rowindex, rowParams, store) { var grid = this.ownerGrid; if (record.data.code == 1) { grid.viewModel.data.code.push(rowindex); } var eCode = record.data.change;//标识出状态的那一列 if (eCode == 'yes') { record.data.asd = '应付'; return 'x-grid-record-warning'; } } }, store: Ext.create("Ext.data.Store", { deferRowRender: false,//不执行默认的render代码 proxy: { type: 'ajax', url: 'resources/data/gridchange.json' }, root: { text: 'All', id: 'all', expanded: true } }), columns: [{ text: 'name', flex: 1, dataIndex: 'name' }, { text: 'price', flex: 1, dataIndex: 'price' }, { text: '是否作废', flex: 1, dataIndex: 'change' }, { text: '废', flex: 1, dataIndex: 'asd' }, { text: '废', flex: 1, dataIndex: 'code' } ] });