Remember checkbox value when changing page (with server-side processing)
Remember checkbox value when changing page (with server-side processing)
Hi,
This is a great tool - I've gone through loads in the last week and this seems to be the best by far - mostly because of the ease to fit within current site constraints, and allows a high level of customisation!
I'm using dataTables with a potentially large dataset (up to around 10000 rows), so am using the server side processing to grab the data. This works fine, and I can sort and paginate. However, each row includes a checkbox - and when I move from one page to the next and back again, it doesn't remember the checkbox value (obviously - as the record is being pulled from the database).
I guess what I need to do is:
1) On each previous/next action record the checkboxes that are ticked in a cookie or hidden form field.
2) On each page load (after previous/next has been clicked) check the hidden value to see if any of the checkbox IDs on the current page have been selected, and if so tick the box.
Is this something that's already included as a plug in? I'm not a jQuery expert I'm afraid, so if there isn't already something can you give me a kick in the right direction to the right functions so I can try and create something? :)
Thanks for your help!
Kev
This is a great tool - I've gone through loads in the last week and this seems to be the best by far - mostly because of the ease to fit within current site constraints, and allows a high level of customisation!
I'm using dataTables with a potentially large dataset (up to around 10000 rows), so am using the server side processing to grab the data. This works fine, and I can sort and paginate. However, each row includes a checkbox - and when I move from one page to the next and back again, it doesn't remember the checkbox value (obviously - as the record is being pulled from the database).
I guess what I need to do is:
1) On each previous/next action record the checkboxes that are ticked in a cookie or hidden form field.
2) On each page load (after previous/next has been clicked) check the hidden value to see if any of the checkbox IDs on the current page have been selected, and if so tick the box.
Is this something that's already included as a plug in? I'm not a jQuery expert I'm afraid, so if there isn't already something can you give me a kick in the right direction to the right functions so I can try and create something? :)
Thanks for your help!
Kev
This discussion has been closed.
Replies
I'm not aware of any source code which is available which will do exactly what you want (although I'm reasonably sure similar questions have been asked before - so it's certainly do-able!).
What you need to do is add event listeners to your checkboxes (using fnDrawCallback() which is run every time DataTables draws a new page, be it pagining, sorting, filtering etc). These events should maintain an array of indexes showing what checkboxes are ticked or not. Then also using fnDrawCallback() you can look through this list and see if any of the checkboxes which have just been added to the page should be checked or not, and take appropriate action.
How does this sound?
Regards,
Allan
I'll give that a bash and when(!) I've solved it will paste the code here...
Cheers,
kev
Can you post the code?
Thanks :-)
http://datatables.net/forums/comments.php?DiscussionID=582&page=1#Item_0
Good Luck!