Datatbles - Custom Search not working

Datatbles - Custom Search not working

Noodles12Noodles12 Posts: 113Questions: 41Answers: 2
edited March 2023 in Free community support

I have added a Custom Search to a page that uses Datatables. The custom search works on live.datatables.net, but not on my local system. Here is my code - https://live.datatables.net/jebatava/1/edit

$('#myInputTextField').on( 'keyup', function () {
table.search( this.value ).draw();
});

As you can see "myInputTextField" works well here, but it does not work in my environment. Any ideas what could be the reason? Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    The test case has this error causing the search to not work:

    Uncaught ReferenceError: table is not defined

    You are creating the table variable within the context of the document.ready() function. But your event handler is outside of this function so it doesn't have access to the table variable. Move the event handler inside the document.ready() function:
    https://live.datatables.net/jebatava/2/edit

    Now this error:

    Uncaught ReferenceError: filtered is not defined

    We need to create the filtered variable.

    With these fixes the test case runs. If this doesn't help with your issue then check the browser's console for errors.

    Kevin

  • Noodles12Noodles12 Posts: 113Questions: 41Answers: 2

    That did it. Thankyou very much!!

Sign In or Register to comment.