Set the search field's value and sort the dataTable

Set the search field's value and sort the dataTable

MajesticMajestic Posts: 14Questions: 7Answers: 0

Hello,
I retrieve the cell's value on double click and set the search's value to the cell's value in order to sort by the cell's value.
The issue I have is the dataTable is not updating when I set the search's value, it only works when I type on keyboard.
Is there a way to make it works as I expected ?

Here's my code :

$(document).ready(function() {

    $('#dataTables tbody').on('dblclick', 'td', function () {
    searchValue = currentTable.cell(this).data();
    });
});
'rowCallback': function(row, data, index) {
            $(row).dblclick(function() {
                $('#dataTables_filter input').val(searchValue);
            });
}

Thank you !

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited January 2019 Answer ✓

    Instead of populating the search input value you want to use the search() API. Remove the code you put in the rowCallback and update your dblclick event to use the search API, for example:

        $('#dataTables tbody').on('dblclick', 'td', function () {
        searchValue = currentTable.cell(this).data();
        $('#dataTables').DataTable().search(searchValue).draw();
        });
    

    Kevin

  • MajesticMajestic Posts: 14Questions: 7Answers: 0

    You're right, I should have take a look to the search API. It's working fine !
    Thank you Kevin, it's awesome !

This discussion has been closed.