DataTable search to simulate tableClick when search results == 1

DataTable search to simulate tableClick when search results == 1

tj26tj26 Posts: 11Questions: 6Answers: 0

Hello,

I have a DataTable, when I type in the Search box the number of items in the table reduces to those that match as expected. What I am trying to do is when the text in the search box matches 1 table value only and the user presses the Enter key I wish for it to simulate a tableclick() call on the one item displayed in the DataTable. Is it possible to know the number of rows in the table that the search has matched after an Enter key press?
Is simulating a tableClick() possible?

Currently when a user mouse clicks on a table entry it will run this:

        function tableClick() {
                var data = locTable.row(this).data();
        }

This is what I have so far:

$('#locTable_filter input').bind('keyup', function(e) {         
if(e.keyCode == 13) {

}
});

Thank you very much :)

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586
    Answer ✓

    You could use events to determine the table size after the search - take a look at draw or search, one of those should do the trick for you,

    Colin

  • tj26tj26 Posts: 11Questions: 6Answers: 0
    edited March 2023

    My Answer:

        $('#locTable_filter input').bind('keyup', function (e) {
                    if (e.keyCode == 13) {
                        var count = locTable.rows({page:'current'}).count();                
                        if(count == 1) 
                        {
                            $(locTable.row( { search: 'applied' } ).node()).click();                            
                        }
                    }
                });
    
Sign In or Register to comment.