Question about the checkbox check box selected when jquery-ajax-php + ajax is paging

Source: Internet
Author: User
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. WhenPAGEWhen the content changes, repeatPAGERendering. 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 uniquerowidWhen rendering the pagerowidDetermines whether the current item is selected.

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.