• Post Reply Bookmark Topic Watch Topic
  • New Topic

Maintaining the state of checkbox in pagination

 
Manish Sahni
Ranch Hand
Posts: 41
Java Netscape Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I have retrieved 10 records/page along with the check boxes in front of each records from the database and also done pagination in it.

The problem i am getting is whenever i select the check box and go to 2nd page and again come back on previous 1st page , the check box state is refreshed and i do not see any checked check boxes.

How can i maintain the state of a check box in pagination??


 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have no idea how you're implementing your pagination, whether or not you're going back to the server when you return to a previous page, how the initial state of the checkboxes is determined in the first place, etc.

If you're talking about this:

1) I hit the database and get the first page's results
2) I check some checkboxes
3) I click on the next page and go to the server to get page two
4) I click some checkboxes there as well
5) I click to go back to page one and the boxes I checked are no longer checked

then the problem is obvious: the checkboxes aren't being persisted, and the page is being refreshed, so of course their values are re-initialized. You'd need to either persist the changes when you go to the next page, or Ajax an update when a checkbox state changes, or...

If you're doing the pagination "in-place", i.e. just updating the pagination div, you *could* keep the checkbox states in JavaScript and update them in one shot when you submit the changes.

But with the information given, it's difficult to help.
 
Manish Sahni
Ranch Hand
Posts: 41
Java Netscape Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David ,

I am talking about exactly this:-


1) I hit the database and get the first page's results
2) I check some checkboxes
3) I click on the next page and go to the server to get page two
4) I click some checkboxes there as well
5) I click to go back to page one and the boxes I checked are no longer checked

How to persist the changes in checkbox?? any link or help would be appreciable.
 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi manish,
just store the id's of selected checkboxes in a hidden field as a comma separated value.
hope this helps
 
subhash kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you save the state of check box when user move to page two.
then restore the saved state, when user moves back to the page one.
But
if user move to the page three
then your requirement says you have to save the state of check boxes of both previous pages. ?
if it is so
then you have to decide the depth up to which you maintains that?
Other factor can be like correctness to check the same boxes whose states you have saved
because if records modified ?
take care for these steps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!