Purpose: display all data by page. Instead of querying all data, you can obtain a fixed number of entries each time. In addition, the selected data ID on each page can be saved, and the selected data can be submitted together for corresponding operations. For example, select 2 items on the first page, 3 items on the second page, and 5 items for submission... purpose: display all data by page. Instead of querying all data, you can obtain a fixed number of entries each time. In addition, the selected data ID on each page can be saved, and the selected data can be submitted together for corresponding operations. For example, if two are selected on the first page, three are selected on the second page, and five are submitted, if the first page is returned, the selected data is displayed, and the second page is returned, the selected data will also be displayed, and so on. The selected data will be deselected several times and displayed several times without any problems. In short, no bug is found in page turning whether selected or canceled.
How can this be achieved ?.. Paging is fine, but this check box will refresh the next page.
Reply content:
Purpose: display all data by page. Instead of querying all data, you can obtain a fixed number of entries each time. In addition, the selected data ID on each page can be saved, and the selected data can be submitted together for corresponding operations. For example, if two are selected on the first page, three are selected on the second page, and five are submitted, if the first page is returned, the selected data is displayed, and the second page is returned, the selected data will also be displayed, and so on. The selected data will be deselected several times and displayed several times without any problems. In short, no bug is found in page turning whether selected or canceled.
How can this be achieved ?.. Paging is fine, but this check box will refresh the next page.
Two solutions
Solution 1
---
1. Each page is a separate container (p ).
...
2. When loading a new page, first check whether the page has been loaded, for example, loading page 4
// The Code only indicates if ($ ('. page-4 ','. content '). length> 0) {$ ('. page ','. content '). hide (); $ ('. page-4 ','. content '). show ();} else {page4 = render_page (load_page (4); // get the structure of page4 $ ('. page ','. content '). hide (); $ ('. content '). append (page4 );}
In this way, you can save the page information when switching the page.
Solution 2
---
Create an object to store page data and allow it to support custom events. WhenPAGE
When the content changes, repeatPAGE
Rendering. This is actually an MVC solution.
The following code is hand-written only for illustration. Do not use it directly.
// You can use EventEmitter and other event libraries for support. For simplicity, I use jQuery var PAGE =$ ({current:-1, data :{}}); PAGE. extend ({fetch: function () {$. get ('url', function (data) {this. data [current_page] = data this. trigger ('value _ change') ;}, show: function (page) {PAGE. current = page; if (this. data [page]) {this. trigger ('value _ change');} else {this. fetch (page) ;}},}); PAGE. bind ('value _ change', function () {render_page () ;}); var render_page = function () {if (PAGE [PAGE. current]) {// by PAGE [PAGE. current] Content Rendering p # page content} else {throw ('error') ;};$ ('input [type = "checkbox"] ', '# page '). change (function () {// Update PAGE content PAGE. data [current_page] [item] = value PAGE. trigger (value_change );});
Use an array variable a [] to save the selected id;
Is the html part of the previous page deleted or hidden during paging? If it is deleted, it will certainly disappear.
This is like a shopping cart, right? Items selected on each page are thrown into the shopping cart and then processed in batches.
I used the shopping cart class in CodeIgniter to handle this situation. The principle is to use session to store the selected ID. Each ID will generate a uniquerowid
When rendering the pagerowid
Determines whether the current item is selected.