How to check/uncheck all checkboxes with pagination

How to check/uncheck all checkboxes with pagination

awfjfiqawfjfiq Posts: 5Questions: 1Answers: 0

Hello, i'am working on a very old project using datatables version 1.8.1. So i'am wondering how can i check/uncheck all checkboxes which are on multiple page. I'am using ajax-source to rendering the table and the bServerSide is set to true.

$('form table input[name="check_all"]').on('change', function() { $(this).closest('table').find('input[type="checkbox"]:not(:disabled)').prop('checked', $(this).prop('checked')); });

This code help me to select all checkbox on the current page only. What i want is to select all checkboxes.

I found the code below on the forum but its shows an error that dt.rows() is not a function maybe due to version difference ?
dt.rows().nodes().to$().find

Thanks in advance for your help,

Answers

  • colincolin Posts: 12,877Questions: 0Answers: 2,198

    It would be worthwhile updating to the most recent version as 1.8 is very old now! Would that be possible?

    Colin

  • awfjfiqawfjfiq Posts: 5Questions: 1Answers: 0

    @colin I agree with you but since it is a very old project, we are not planning to update plugins for the moment. is there any solution without updating data-tables? Thanks.

  • kthorngrenkthorngren Posts: 14,086Questions: 25Answers: 3,322

    With server side processing the only table data available at the client are the rows being shown on the page. There is nothing built-in to keep track of checkboxes with server side processing. You will need to keep track of the checkboxes yourself. I'm not familiar with the DT 1.8 API's but here are a couple ideas:

    1. For each table draw check the select-all checkbox and use your code above to check all on the page for display.
    2. Save the checkbox state in the DB and render the checkbox state based on the value in the DB.

    Kevin

  • awfjfiqawfjfiq Posts: 5Questions: 1Answers: 0

    Hi, I just found in legacy documentation that there is a equivalence of dt.rows().nodes() => fnGetNodes(), i've also found that we could use fnGetHiddenNodes() for invisible checkboxes (off-screen) but i do not know if there is an equivalence of fnGetHiddenNodes() for DT1.8. Also, i am looking for an equivalence for to$() or toJQuery() in the same version.

  • awfjfiqawfjfiq Posts: 5Questions: 1Answers: 0

    Finaly i succeed by adapting my code to code of this page of Dt. I have made that all checkbox is chosen by default in my controller and stock the unchecked box's id into an array and when i reload the page, i check if the id of checkboxes is included in this array, if so, it will uncheck the checkbox.
    Thanks a lot for your helps.

Sign In or Register to comment.