How to get every checked checkbox value in DataTable using PHP?

How to get every checked checkbox value in DataTable using PHP?

fmsthirdfmsthird Posts: 8Questions: 2Answers: 0

Hi, I am trying to get all the values of the selected checkbox in my DataTable table.

Everything seems to be working well until when my table's data is paginated.
When I submit the Form where my DataTable is, only the checked checkbox value in the current page is getting fetched.

May I know how I can get all the value of the checked checkbox across all pages?

Thanks in advance.

Answers

  • kthorngrenkthorngren Posts: 6,264Questions: 21Answers: 1,373

    Everything seems to be working well until when my table's data is paginated.

    Do you mean you enabled "serverSide: true"?

    May I know how I can get all the value of the checked checkbox across all pages?

    If you have Server Side Processing enabled then the only data available in the client is the data on the page being shown. Would you be able to use client side processing by turning of "serverSide: true"?

    If you don't have server side processing enabled then please provide more details of what you are doing. A link to your page or a test case will help us understand what you have to offer suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • fmsthirdfmsthird Posts: 8Questions: 2Answers: 0
    edited September 12

    hi @kthorngren thanks for noticing this one. Actually I have the same issue with this one https://datatables.net/forums/discussion/comment/97682/

    But I'm new to DataTable that's why I don't really understand how to implement the solution. And if possible I want it to be done from PHP, not in Javascript

    Also, I'm developing from my local machine.

    Here's how I defined my DataTable:

    $('#myTable').DataTable({
          "paging":   true,
          "filter":     true,
          "info":     true,
          "select": true,
          "scrollX": true,
          columnDefs: [
            { orderable: false, targets: '_all' }
          ],
          "order":  [[ 2, "desc" ]],
          "language": { search: '', searchPlaceholder: "Search shipment" },
          "sDom": 'fr<"#buttons">ti<"#pagePrevNext"lp>'
        });
    
  • kthorngrenkthorngren Posts: 6,264Questions: 21Answers: 1,373
    edited September 12

    Sorry, I'm not a PHP coder but suspect the problem is the same as discussed in the thread you linked. Good find BTW! If you use the browser's inspector you will find that the only rows in the DOM are the rows displayed on the page. Datatables keeps a data cache with all the data. As mentioned by the developer in the other thread you will need to use Dattaables API's to get the checkboxes of all pages.

    Kevin

  • fmsthirdfmsthird Posts: 8Questions: 2Answers: 0

    @kthorngren given the code snippet I have above, what would be the adjustments I need to make? How can I use DataTables API's .. ?
    Thanks much

  • kthorngrenkthorngren Posts: 6,264Questions: 21Answers: 1,373

    I haven't tried it but did you try the API that the developer posted in the thread you linked to ?

    dataTable.rows().nodes().to$().find('input[type="checkbox"]').each(function(){
    

    Kevin

Sign In or Register to comment.