How to solve the data loss problem when jqGrid pages, jqgrid pages

Source: Internet
Author: User

How to solve the data loss problem when jqGrid pages, jqgrid pages

When I use jqGrid in a project, I load server data asynchronously, for example, loading data when I click pages or search. This will cause a problem.

Problem description:

When deleting a list in batches, you can select multiple records and select the first record on the current page,

 

Click the next page and select some records. When you click Delete, the selected records on the previous page cannot be deleted.

Solution:JqGrid does not seem to solve this problem, so you can only write your own code to save the selected records. Two jqGrid event methods are required:

/** Multiselect is true, and this event is triggered only when you click the checkbox in the header. ARowids: the id set of all selected rows. It is an array. Status: the boolean variable indicates the selection status of the checkbox. If it is set to true, false is not selected. Whether or not checkbox is selected, aRowids always has a value **/onSelectAll (aRowids, status)/** to trigger this event when selecting a row. Rowid: id of the current row; status: Select status. This parameter is available only when multiselect is set to true **/onSelectRow (aRowids, status)

General Code

// Save the Array var selectIds = new Array (); jQuery ("# gridid") of the selected record "). jqGrid ({onSelectAll: function (aRowids, status) {if (status = true) {$. each (aRowids, function (I, item) {saveIdToArray (item) ;})} else {$. each (aRowids, function (I, item) {deleteIdFromArray (item) ;}}, onSelectRow: function (aRowids, status) {if (status = true) {// select saveIdToArray (aRowids);} else {// cancel deleteIdFromArray (aRowids) ;}}) // save it to the Array function saveIdToArray (item) {var exit = false; for (var I = 0; I <selectIds. length; I ++) {if (item = selectIds [I]) {exit = true; break ;}} selectAssets. push (item) ;}}// delete function deleteIdFromArray (item) {if (selectIds. length> 0) {for (var I = 0; I <selectIds. length; I ++) {if (item = selectIds [I]) {selectIds. splice (I, 1); break ;}}}}

Only the array can be operated.

The above is a small series of solutions to the loss of data selected during the jqGrid page turning, I hope to help you, if you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.