Daniel Gustafsson
Daniel Gustafsson

Reputation: 1827

jquery datatable resets on enter

Im using a jquery datatable and when i type something in my textboxes it searches for the values on every keypress which i like. But when im done searching and i by default press the enter key it emptys the search field. How can i prevent this from happening?

 var oTable = $('#bookings').dataTable({
        "bServerSide": true,
        "bAutoWidth": false,
        "bDestroy": true,
        "bProcessing": true,
        "sAjaxSource": "/Bokningar/PagedData",
        "fnServerData": function (sSource, aoData, fnCallback) {
            $.ajax({
                url: sSource,
                dataType: 'json',
                data: aoData,
                success: fnCallback,
                error: function () {
                    window.location.href = "/Konto/LogOff";
                }
            });
        },
        "sPaginationType": "four_button",
        "oLanguage": {
            "sProcessing": "Laddar...",
            "sLengthMenu": "Visa _MENU_ rader",
            "sZeroRecords": "Inga matchande resultat funna",
            "sInfo": "Visar _START_ till _END_ av totalt _TOTAL_ bokningar",
            "sInfoEmpty": "Visar 0 till 0 av totalt 0 bokningar",
            "sInfoFiltered": "",
            "sInfoPostFix": "",
            "sSearch": "Sök:",
            "sUrl": "",
            "oPaginate": {
                "sFirst": "",
                "sPrevious": "",
                "sNext": "",
                "sLast": ""
            }
        },

Upvotes: 0

Views: 72

Answers (1)

Preview
Preview

Reputation: 35836

Maybe you can try something like this ?

$('.dataTables_filter input').bind('keypress', function(e) {
if(e.keyCode==13){
    e.preventDefault();
    }
});

It is possible that overrides the search event, let me know if it's the case.

Upvotes: 1

Related Questions