jeudi 12 avril 2018

Cant get rows of all pages using datatables with select checkboxes server side

The contend of this post is similar to this post Getting all selected rows with DataTables checkbox plugin with server side, which is still unanswered. But hence i can comment on posts i made a own one, so please forgive me.

I have a Datatable with server side processing and checkboxes in one column. The code of the Datatable is something like this:

var result_datatable = $('#result_table').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": "/api/datatable/get_data",
        "data": function ( d ) {
            d.query = $('#query_input').val();
            d.field = $('#fields_input').val();
            d.sort = $('#sort_fields_input').val();
        }
    },
    "columns": [
        {
            "data": "id",
            "checkboxes": {
                "selectRow": true
            }
        },
        { "data": "filename" },
        { "data": "preview" },
        { "data": "shape.0" },
        { "data": "shape.1" },
        { "data": "tags" }
    ]
    'select': {
        style: 'multi',
        info: true,
        selector: 'td:nth-child(1), td:nth-child(2)'
    },
    "ordering": false
    }
});

With the "select" and "deselect" event I want to porcess some data, here the code of "select" event:

result_datatable.on( 'select', function ( e, dt, type, indexes ) {
    var num_checked = result_datatable.column(0).checkboxes.selected().length;
    console.log(num_checked);
    console.log(result_datatable.column(0).checkboxes.selected());
    //do stuff...
} );

My problem is that the function which prints out all checked rows only prints the checked rows of the current page. I know that the example which is made at https://www.gyrocode.com/projects/jquery-datatables-checkboxes/examples/server-side/server-side-processing/ works fine, but I cant figure out my mistake. To the question asked in the related post, all ids are unique hashes.

Thank you for you help




Aucun commentaire:

Enregistrer un commentaire