Extjs grid checkbox selected by default
(16:21:05)
Reprinted
Tags:Extjscheckboxit |
Category: extjs |
VaR SM2 = new Ext. Grid. checkboxselectionmodel ({
Singleselect: This. is_singleselect,
Renderer: This. checkboxrenderer. createdelegate (this) // Add this Renderer
});
This. Grid = new Ext. Grid. gridpanel ({// list
Border: false,
Height: 300,
Store: ds,
CM: colmodel,
SM: Sm2,
});
// Define Renderer
Checkboxrenderer: function (value, cellmeta, record, rowindex, columnindex, store ){
VaR ROW = This. Grid. getstore (). getbyid (record. ID );
VaR id = row. Get (this. id_key); // This. id_key is the key of a row. You can determine whether to select the row by default or no selection box is displayed.
VaR isselect = false;
// Select the logic
If (! Isselect ){
Return '<Div class = "x-grid3-row-checker"> & nbsp; </div> ';
} Else {
Return '';
}
},
Ext. onready (function () {var testdata = [['1', 'xxxxx'], ['2', 'aaa'], ['3', 'xxyyy'], ['4', 'bbbbb']; var selectvalue = ['bbbbb', 'aaa'] var store = new Ext. data. simplestore ({fields: ['id', 'name']}); var Sm = new Ext. grid. rowselectionmodel ({listeners: {'rowselect': function (SM, rowindex, R) {Ext. log ("select", rowindex, R. get ('name') }}); var grid = new Ext. grid. gridpanel ({width: 800, height: 500, AUT Oscroll: True, store: store, SM: Sm, columns: [Sm, {header: 'sequence number ', dataindex: 'id', sortable: true}, {header: 'name', dataindex: 'name', sortable: true}]}); var v = new Ext. viewport ({items: [grid]}); store. on ('load', function (store, records, options) {var arr = []; for (VAR I = 0; I <records. length; I ++) {var record = records [I]; var ismatch = selectvalue. indexof (record. get ('name '))! =-1; if (ismatch) {arr. push (record) ;}} SM. selectrecords (ARR) ;}, this, {delay: 1000}) store. loaddata (testdata );});
The comments of the questioner on the answer:
Latency is required. Thank you ~~
Other answers
Ext. Grid. checkboxselectionmodel inherits Ext. Grid. rowselectionmodel.
Check the API:
Selectrecords (Array records, [Boolean keepexisting]): void
Select records.
Parameters:
Records: Array
The records to select
Keepexisting: Boolean
(Optional) True to keep existing selections
Returns:
Void
You can traverse the store load event to find your desired record,
Then run grid. getselectionmodel (). selectrecords (
VaR Sm = grid. getselectionmodel (); // obtain the selected model SM. selectall (); SM. selectfirstrow (); SM. selectlastrow (); selectnext (); selectprevious (); selectrange (number startrow, number endrow, [Boolean keepexisting]); selectrecords (Array records, [Boolean keepexisting]); selectrow (number row, [Boolean keepexisting]);