Easyui DataGrid to avoid secondary loading

Source: Internet
Author: User

The first is the principle:

In a data table implemented using the Easyui DataGrid, there are two ways to register the DataGrid component, namely, class and JavaScript,

The class method is to add class= "Easyui-datagrid" to the table label, for example:

<table id= "DG"  title= "class=" Easyui-datagrid "></table>

The JavaScript method is:

$ (' #dg '). DataGrid ({//This fills in the parameters of the initialization DataGrid});

These two registration methods cannot coexist, otherwise it will cause two loads.


Setting the URL in the JavaScript registration method automatically triggers the query, but it is undesirable to implement the query function in this way, because it will render the DataGrid every time the query is rendered again.

Correct is the idea is: Register the DataGrid only once on the page (if you do not need to go to the page directly query, then do not set the URL), and then at query time by obtaining the DataGrid's options to set the URL, and then use the load or reload method to query, the example is as follows:

$ (function () {  
    INITDG ();  
});  
function Querydata () {    
	var opts=$ ("#dg"). DataGrid ("Options");  
    if (null==opts.url| | "") ==opts.url) {  
        opts.url= "xxx.action";  
    }  
    $ ("#dg"). DataGrid ("Reload");  
}  
function INITDG () { 
    $ (' #dg '). DataGrid ({
    	url:s_url,//requires immediate query when URL pagenumber:1 is turned on  
    	,  
    	queryparams: $ (' #form '). SerializeObject ()
    });  
}  


Add: Use reload to overload, there may be a page number display error problems (such as I select the third page, and then enter the query criteria for the query, the results of the query is normal, but the paging parameters will stay on the third page),

Overloading with load does not have this problem



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.