Extjs grid checkbox selected based on data Initialization

Source: Internet
Author: User

Background: Based on business needs, you need to load a lot of data in the grid, and then determine whether the data is selected based on a certain attribute of each data.

Process: google found that a foreigner provided the following methods.

Ext. ajax. request ({method: 'post', url: 'index. php/mapper/get_tag_subfields/', scope: this, params: {id: this. gridB. getSelectionModel (). getSelection () [0]. data. id,}, success: function (xhr) {var json = Ext. decode (xhr. responseText); // make sure to decode for loadData to work // data is formatted, just needto load data storeMapperSubfields. loadData (json. data); // mark checkboxes if (json. data. length) {for (var I = 0; I
 
  

Source Document


However, an error is reported in the red line when I use it. Views [0] cannot be found.

The following is my code:

Ext. ajax. request ({url: '/aaaaaaaaaaa/bbbbbbbbbbbbbbb. do ', method: 'post', params: {methodName: 'aaaaaaaaaaaaa', policyid: policyid, appid: appid}, success: function (response, options) {var result = Ext. JSON. decode (response. responseText); var editTitle = "collection policy" + policyName + 'Operation request modified'; var editPolicyPanelOpers = new PM. view. policy. policyEditOpers ({title: editTitle //, // data: result. data}); // set polic Yid Ext. componentQuery. query ('window # policyeditopers textfield # selectpolicyid') [0]. setValue (policyid); Ext. componentQuery. query ('window # policyeditopers textfield # selectAppid ') [0]. setValue (appid); var operGrid = Ext. componentQuery. query ('window # policyeditopers grid # oper_grid ') [0]; var opersStore = Ext. getStore ('businessoperstore'); if ("undefined "! = Typeof opersStore) {opersStore. loadData (result. data); operGrid. reconfigure (opersStore); for (var I = 0; I <result. data. length; I ++) {var rec = operGrid. store. getById (result. data [I]. businessoperid); // json. data [I]. getId () if (rec. data. selected = true) {// select all records have's 'opergrid. getSelectionModel (). select (rec, true, false) ;}}// you can specify appid editPolicyPanelOpers. show () ;}, failure: function () {var o = Ext. JSON. decode (response. responseText); // alert (o. msg); Ext. msg. alert ('prompt information', o. message );}});

Check the select (rec, true, false) method. The rec parameter is either an index or a record instance.
At the same time, he said it was a rendering problem. It indicates that I am calling something wrong.
The next step is self-defeating: I checked the source code and found that the property selected is private. It cannot be used to set whether to select or not.
After several hours, I thought of my colleague again.
Finally, I practiced it patiently. This is indeed the problem. The problem was solved, but it took one afternoon and one night.

The following is a code snippet:

init:function(){this.control({  'policyeditopers grid#oper_grid':{  afterrender:this.selectModel  }});},selectModel:function(){Ext.Msg.alert('selectModel','test'); var operGrid = Ext.ComponentQuery.query('window#policyeditopers grid#oper_grid')[0];for (var i = 0; i < operGrid.getSelectionModel().store.data.items.length; i++){            var rec = operGrid.store.getById(operGrid.getSelectionModel().store.data.items[i].data.businessoperid); // json.data[i].getId()            if (rec.data.selected == true){ // select all records have have 's'            operGrid.getSelectionModel().select(rec,true,false);            }        }}



Related Article

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.