how to use filter

how to use filter

anshikanshik Posts: 2Questions: 1Answers: 0

https://datatables.net/reference/api/filter()

I put data-filter to td attributes.

<td class="text-right" data-filter="{{ obj.id }}">{{ obj.last_status_change|user_timezone:request|date:"SHORT_DATE_FORMAT" }}</td>

I can see list of data-filter in console

dataTable
    .column( 3 )
    .nodes().filter( function ( value, index ) {
        console.log($(value).data('filter'));
    })     

I can apply function to filtered data:

dataTable
    .column( 3 )
    .nodes().search( function ( value, index ) {
        return $(value).data('filter')>33876;
    })    

filter() returns DataTables.Api (type)
How i can show filtered data in current table, and return source table back?

like in search:

    $('#searchinput').on( 'keyup change', function () {
        dataTable.search($(this).val()).draw();
    } );

    $('#searchclear').on("click", function() {
        $('#searchinput').val("");
        dataTable.search('').draw();
    });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    The filter() method only filters the API object's data - not the table itself. From its documentation:

    This method should not be confused with search() which is used to search for records in the DataTable - i.e. the filter method does not change the rows that are displayed in the DataTable.

    Furthermore, the search() documentation notes that it does not accept a function.

    If you want to apply a function for a search you need to use a plug-in function.

    Allan

  • anshikanshik Posts: 2Questions: 1Answers: 0

    Thank you, Allan.
    After few hours it works :)

This discussion has been closed.