Search / filter option on keypress enter...

Search / filter option on keypress enter...

Hendrik_SHendrik_S Posts: 24Questions: 10Answers: 0

This question is about the default input search / filter option. It can be the case that the input is in the view of the visitor, but the table not. In that case the visitor can not see that something is happening with the table, because it's not in the viewport. I think this can be very confusing for a visitor. In that case the visitor will probably press enter.

I think a better solution is to jump to the table id when pressing enter in the search / filter input. That's maybe something that can be the case by default in a next version.

With:

table.on('click', function(){
alert('test');
});

It's not working on the toolbar, but only the table itself. Now i also have something like:

    initComplete: function(){
        $('.dataTables_filter input').on('keypress', function(e){
            var code = e.keyCode || e.which;
            if (code == 13) {
                 location.hash = "#" + table.table().node().id;
            }
        });
    },

The "table" is coming from:

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

But if you have multiple tables on one page, probably it's working incorrect, because the "on keypress" is on all the filter inputs of all tables. So my question is...how i can i get the node of the filter input (or toolbar) of the corresponding table? Or what's the best clean solution to do that? I don't wanna repeat id's or something, because that's not that clean.

So actually i want:

$('.dataTables_filter input')

but only for the corresponding table without using the id #example again And is it the correct way to define it in "initComplete" or i can better do it differently?

This discussion has been closed.