change filter behaviour on keypress

change filter behaviour on keypress

laralara Posts: 2Questions: 1Answers: 0

Hi,
is it possible to change the behaviour of the dataTable filter on keypress? I would like it to not remove elements from the DOM but instead add a class to the row not matching the filter.
Thanks!

Answers

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14

    The way you'd do something like that is to intercept the keypress using Jquery and write a custom function to do whatever logic you may want (in your case add classes). I'm not sure how you're implementing the filters so I can't really be any more helpful than that.

  • laralara Posts: 2Questions: 1Answers: 0

    hi Rpiechura, and thank you for your reply. I am already detecting keypress on the filter input, but it doesn't stop the default behaviour to take place. I don't want to change the default code of dataTables, as I have to do this operation only in one spot. My datatable is configured as follows:

        "aLengthMenu": [
            [25, 50, 100, 200, -1],
            [25, 50, 100, 200, "All"]
        ], 
        "iDisplayLength" : -1,
        "sPaginationType": "full_numbers",
        "bPaginate": false,
        "bInfo": false,
        "aaSorting":{},
        "bStateSave": true,
        "bRetrieve": true,
        "bDestroy": true,
        "bFilter": true,
        "fnStateLoadParams": function (oSettings, oData) {
            oData.oSearch.sSearch = searchstring;
        },
        "aoColumns": [
            { "bSortable": false },
            {},
            {},
            {},
            {},
            {},
            {},
            {},
            { "bSortable": false },
            { "bSortable": false }
        ]
    

    and my jquery function

    $(document).on('keyup', ".dataTables_filter input", function() { ... });

    And nothing else is being done with filters.
    Is this possible without having to modify the dataTables code?

    Thank you for your help!

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
    edited June 2014

    Hmm, I'm used to doing things with server side processing where you can intercept the filter calls entirely since you're making ajax requests for the data. I don't know how you'd do it using client side processing. I wish I could be more help but I'm stumped.

    (As such, you may want to mark my response as not an answer so that this goes back to the 'unanswered' portion of the forums.)

This discussion has been closed.