Extjs grid checkbox selected by default

Source: Internet
Author: User
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]);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.