EasyUI learning notes --- Datagrid real paging data query, easyui --- datagrid

Source: Internet
Author: User

EasyUI learning notes --- Datagrid real paging data query, easyui --- datagrid

In my opinion, the EasyUI Datagrid component is still very powerful. I encountered a paging request problem during my use, which had been solved for one day. Next I will share my problems.

// Datagrid data table Rendering

$ ("# Dg"). datagrid ({
Loader: function (param, success, error ){
Var pageNumber = param. page;
Var pageSize = param. rows;
$. Ajax ({
Type: "get ",
Url: url,
DataType: 'jsonp ',
Data: "pageNum =" + pageNumber + "& pageSize =" + pageSize,
Success: function (data ){
If (data. code = 0 ){
Var arr = data. result. content;
$ ("# Dg"). datagrid ('loaddata', {total: data. result. page. totalRecord, rows: arr })
}
},
Error: function (){
Error. apply (this, arguments );
}
});
}
})

 

The input parameters include param, success, and error. Optional.

Here I mainly use param And param has param. page (page number) and param. rows (number of lines displayed on each page) has two attributes. this parameter is required because the page is to be queried after loading;

The first problem I encountered was cross-origin. I will not go into details here if I have mentioned this in my previous article;

The second step is how to render the data returned by the request to the table. Because it is a real page, the data queried each time is only the data on the current page, not all data, however, the total number of data displayed in the footer must be all data.

Finally, we found that the loadData method can input a json data $ ("# dg "). datagrid ('loaddata', {total: data. result. page. totalRecord, rows: arr }).

3. Because I have enabled the loadMsg attribute, the status of loading is displayed when the background data is requested, but the status is not hidden after the request is successful.

OnLoadSuccess: function (data ){
// If the query is successful, the loading status is hidden.
$ (This). datagrid ("loaded ");
}

Hide the loading status after successful data loading

4. Click the next page to query

// Click the next page
$ ('# Dg'). datagrid ('getpager'). pagination ({
// The operation executed by the refresh button
OnBeforeRefresh: function (){},
OnSelectPage: function (pageNumber, pageSize ){
$ ("# Dg"). datagrid ('loading'); // display the loading information
$. Ajax ({
Type: "get ",
Url: url,
DataType: 'jsonp ',
Data: "pageNum =" + pageNumber + "& pageSize =" + pageSize,
Success: function (data ){
If (data. code = 0 ){
// Fill in the table after the data is returned successfully
Var arr = data. result. content;
$ ("# Dg"). datagrid ('loaddata', {total: data. result. page. totalRecord, rows: arr })
}
},
Error: function (){
Error. apply (this, arguments );
}
})
}
});

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.