3

I've been trying to get hold of the hidden column data for all filtered rows, when iterating through them.

        var table = $('#'+dataTableSelector).dataTable();

        table.$('tr', {"filter":"applied"}).each( function () {
            var row = this;
        });

Obviously row refers to the TR instance of the datatable; However, if I access the children elements of the TR, these only contain the visible columns for the row in question.

I want to access all data for the row in question, but when I try to reference the datatable, or table.row(this).node() within the each function it doesn't work - row is not a function.

How can I get all data for the rows for which filters are applied?

2 Answers 2

9
$(dataTableSelector).DataTable().rows( { filter: 'applied' } ).every( function () {
    var row = this.data();
});

This will get the DataTable instance (where dataTableSelector is your Table ID from your HTML markup), and then get all rows that has a filter applied, and then iterate over all those rows.

Rows that do not match the filters applied (and thus are not visible in your DataTable) will not be within the results returned by rows( { filter: 'applied' } )

You can access each column of the row by row[0], row[1] etc; row will be an array of all columns, including non-visible columns.

Sign up to request clarification or add additional context in comments.

Comments

0

If you use the DataTables API as @Resurgent suggested, then the data for the hidden columns will be returned still. So use that suggestion, or something like table.rows({filter:'applied'}).data() if want the data in an array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.