Extjs Grid checkbox selected based on data initialization __js

Source: Internet
Author: User

Background: Depending on the business requirements, you need to load a lot of data into the grid, and then determine whether the data is selected based on one of the properties of each piece of data.

Process: Google a bit, found a foreigner to provide the following method.

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, JU
            St Needto Load Data storemappersubfields.loaddata (json.data);
                    Mark Checkboxes if (json.data.length) {for (var i = 0; I <json.data.length; i++) { var rec =this.gridc.store.getbyid (json.data[i].id);
                       Json.data[i].getid () if (Rec.data.field_type = =//Select all records have have ' s ')
                    This.gridC.getSelectionModel (). Select (Rec,true,false);
            }}}, Failure:function () {ext.getbody (). unmask (); Alert (' AJAX Failure:unabLeto process call ');
}
    }); }, this);


Source Document


But when I use the Red line part of the error. Say Views[0] can't find it.

Here's My Code:

 Ext.Ajax.request ({url: '/aaaaaaaaaaa/bbbbbbbbbbbbbbb.do ', Method: ' Post ', para  
			        MS: {methodname: ' aaaaaaaaaaa ', Policyid:policyid, appid:appid},
			            Success:function (response, options) {var result = Ext.JSON.decode (Response.responsetext);
				        VAR edittitle= ' acquisition strategy ' +policyname+ ' Operation request modification ';
				                var editpolicypanelopers = new PM.view.policy.PolicyEditOpers ({title:edittitle//,
				        Data:result.data}); Set PolicyId 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].bu Sinessoperid);
			                    	Json.data[i].getid () if (rec.data.selected = = true) {//Select all records have have ' s '
			                    Opergrid.getselectionmodel (). Select (Rec,true,false);
			        }}//Set AppID editpolicypanelopers.show ();  
			           }, Failure:function () {var o = Ext.JSON.decode (response.responsetext); 
			             alert (o.msg);
			        Ext.Msg.alert (' Cue message ', o.message);  }  
			    });

Consulted the method of select (Rec,true,false). Say rec This parameter is either index or an instance of the record.
Asked at the same time, he said it was a matter of rendering. Say I'm calling the wrong place.
And then there's your own mess: Check the source code and find the property selected private. It cannot be set to be checked or not.
After a few hours, I thought of my colleague's words.
Finally, I patiently went to practice. Sure enough, that's the problem. The problem was solved, but it took a whole afternoon plus one night.

Here is the code fragment:

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.getselecti Onmodel (). Select (Rec,true,false);}}}
	



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.