How to redraw table on custom keyup event?

How to redraw table on custom keyup event?

CamoCamo Posts: 33Questions: 6Answers: 0
edited June 2021 in Free community support

Hi, I try to do some custom search for datatable, so according the cunstom range filter example I tried to call appDataTable.draw(); But it throws me an error: draw() is not a function. If I remove it, it listen on press enter and it works, but it also reorder the table (cause input is in the same th as order arrows). I need to call it on keyup. What am I doing wrong?

        jQuery( document ).ready(function($) {

            $('#datatable th input')
                .on('click', function(e) { return false })  // Prevent reorder
                .on('keydown', function(e) {  
                    let code = e.keyCode || e.which;
                    if( code === 13 ) return false;
                });

            $('#datatable th input').on('keyup', function(e) {
                    appDataTable.draw();  // This is from documentation but throws me an error.
                });

            $.fn.dataTable.ext.search.push(
                function( settings, data, dataIndex ) {

                    var result = true;

                    var codeInputVal = $('#code').val();
                    var valueVal = $('#value').val();
                    var typeVal = $('#type').val();

                    if( valueVal && parseInt(data[2]) !== parseInt(valueVal) ) result = false;
                    else if( typeVal && data[1].indexOf(typeVal) < 0 ) result = false;
                    else if( codeInputVal && data[3].indexOf(codeInputVal) < 0 ) result = false;

                    return result;
                }
            );
        });

Answers

Sign In or Register to comment.