Get all rows from DataTable including those filtered out

Si Stone

I am using the excellent jQuery Datatables plugin.

I have a simple table, where the first column of each row is a checkbox with class .chk-items.

I want users to be able to select a number of rows, and then perform an action on all those rows which have had the checkbox checked. This may include checking one or more boxes, using the SEARCH facility to filter, then checking other boxes. This of course does mean that some rows which are checked are no longer visible (i.e. they have been filtered out).

I currently have the following to handle the checked rows:

var tableData = new Array([]);
var idx = 0;
$('.chk-items').each(function() {
//Add checked items to next tab
    if($(this).is(':checked')) {
        //Get the selected row data into an array
        var rowData = (this).closest('tr').children("td").map(function() {
            return $(this).text();
        }).get();
        tableData[idx] = rowData;
        idx = idx + 1;
    }
})

However, this doesn't work when one of the checked rows is filtered out by a search.

Can anyone suggest a way to change this to also handle checked rows filtered out by the search?

Gyrocode.com

SOLUTION

Use DataTables API method $() to perform a jQuery selection action on the full table.

var table = $('#example').DataTable();

// ... skipped ...

var tableData = [];
table.$('.chk-items').each(function() {
   // Add checked items to next tab
    if($(this).is(':checked')) {
        // Get the selected row data into an array
        var rowData = $(this).closest('tr').children("td").map(function() {
            return $(this).text();
        });

        tableData.push(rowData);
    }
});

DEMO

See this jsFiddle for code and demonstration.

LINKS

See jQuery DataTables - How to add a checkbox column for more information on using checkboxes with jQuery DataTables.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

get filtered embeded elements from all class on mongoengine

From Dev

How to get a subset DataTable from another DataTable filtered by few column values?

From Dev

Create a new regular table from visible and filtered rows of DataTable

From Dev

rowEdit filtered rows on dataTable Primefaces

From Dev

How get all rows values into a string from datatable?

From Dev

DataTable - easy way to get all selected rows in jQuery

From Dev

How to get filtered Data result set from jQuery Datatable

From Dev

What will filter return if all the elements are filtered out ??

From Dev

Get all files in folder including those with long (>256 characters) path + name

From Dev

How to get data from all selected rows in datatable?

From Dev

How do I get the data from the selected rows of a filtered datatable (DT)?

From Dev

How to get all class properties (in Python) of a GAE polymodel including those defined via @property

From Dev

How to prevent all-filtered-out row label values from appearing in a pivot table?

From Dev

Getting the number of affected rows including those not changed

From Dev

Get the list filtered values of a datatable

From Dev

How to get a subset DataTable from another DataTable filtered by few column values?

From Dev

Excel filtering all cells in column instead of those filtered

From Dev

How to select all joined rows from 2 tables including null

From Dev

How to get filtered value on Primefaces lazy datatable?

From Dev

Create a new regular table from visible and filtered rows of DataTable

From Dev

Get all fields from activerecord, filtered by a column in a different table

From Dev

How get all rows values into a string from datatable?

From Dev

how to get all filtered rows from tablesort.js

From Dev

GXT3: How to get all items from a TreeStore including the ones filtered out

From Dev

Select all from table where the rows has the highest id of all those with the same foreign keys

From Dev

Get filtered rows from devexpress gridview c#

From Dev

Joining tables to get all rows from left and all rows from right including unmatched rows

From Dev

Jquery Datatable get all filtered data across multiple pages

From Dev

How to serialize on all rows not on the filtered ones in Webix datatable

Related Related

  1. 1

    get filtered embeded elements from all class on mongoengine

  2. 2

    How to get a subset DataTable from another DataTable filtered by few column values?

  3. 3

    Create a new regular table from visible and filtered rows of DataTable

  4. 4

    rowEdit filtered rows on dataTable Primefaces

  5. 5

    How get all rows values into a string from datatable?

  6. 6

    DataTable - easy way to get all selected rows in jQuery

  7. 7

    How to get filtered Data result set from jQuery Datatable

  8. 8

    What will filter return if all the elements are filtered out ??

  9. 9

    Get all files in folder including those with long (>256 characters) path + name

  10. 10

    How to get data from all selected rows in datatable?

  11. 11

    How do I get the data from the selected rows of a filtered datatable (DT)?

  12. 12

    How to get all class properties (in Python) of a GAE polymodel including those defined via @property

  13. 13

    How to prevent all-filtered-out row label values from appearing in a pivot table?

  14. 14

    Getting the number of affected rows including those not changed

  15. 15

    Get the list filtered values of a datatable

  16. 16

    How to get a subset DataTable from another DataTable filtered by few column values?

  17. 17

    Excel filtering all cells in column instead of those filtered

  18. 18

    How to select all joined rows from 2 tables including null

  19. 19

    How to get filtered value on Primefaces lazy datatable?

  20. 20

    Create a new regular table from visible and filtered rows of DataTable

  21. 21

    Get all fields from activerecord, filtered by a column in a different table

  22. 22

    How get all rows values into a string from datatable?

  23. 23

    how to get all filtered rows from tablesort.js

  24. 24

    GXT3: How to get all items from a TreeStore including the ones filtered out

  25. 25

    Select all from table where the rows has the highest id of all those with the same foreign keys

  26. 26

    Get filtered rows from devexpress gridview c#

  27. 27

    Joining tables to get all rows from left and all rows from right including unmatched rows

  28. 28

    Jquery Datatable get all filtered data across multiple pages

  29. 29

    How to serialize on all rows not on the filtered ones in Webix datatable

HotTag

Archive