dataTable.NET the search box enter each letter once a search problem

When using dataTable.NET, through the simple setting can add a search box to retrieve the whole table.

$('#test-listing')
    .on('order.dt', function () {
        var table = $('#test-listing').dataTable();
        var currentSort = table.fnSettings().aaSorting;
        // do something here
    })
    .on('search.dt', function () {
        var value = $('.dataTables_filter input').val();
        // do something here
    })
    .on( 'init.dt', function () {
        // fired when DataTables has been completely loaded.
        firstTimePageLoad = false;
    } )
    .DataTable({
        paging: false,
        ordering: true,
        fixedHeader: true,
        "search": {
            "search": searchText
        },
        order: defaultSort,
    });

When the search box input, each input keystroke triggers "seatch.dt" the function, shielding method is to keyup event in the search box will be unbind, bind function again he wants.,

$('.dataTables_filter input').unbind();
$('.dataTables_filter input').bind('keyup', function(e){
    if(e.keyCode == 13) {
        var table = $('#test-listing').dataTable()
        table.fnFilter(this.value);
        return false;
    }
});

The above function will be when you press the enter key, it operates the fiter.

Note that, in actual use, when you press the enter key addition can fiter, will trigger other actions form the click of the button, the cause may be related to browser,

Reference to the following link,

 

Guess you like

Origin www.cnblogs.com/sipher/p/11235507.html