searchCols (initial filter) not applying custom filter ($.fn.dataTable.ext.search)

searchCols (initial filter) not applying custom filter ($.fn.dataTable.ext.search)

ChazyChazy Posts: 4Questions: 2Answers: 0

For some reason the searchCols option is not applying the custom filter pushed to the $.fn.dataTable.ext.search array:

searchCols: [ { search: '1' } ],

Is there any way to trigger my custom filter before or after the table is drawn? Like using draw() inside initComplete function?

Or a way to have the dt object inside initComplete?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    The search plugin will run each time the table is drawn. For example each time draw() is calls, anytime the table is searched, paged or sorted. Using searchCols: [ { search: '1' } ], isn't necessarily telling the search plugin to search for the value 1 in the column.

    Is there any way to trigger my custom filter before

    Initialize it before initialize Datatables.

    after the table is drawn?

    Typically use draw().

    Or a way to have the dt object inside initComplete?

    Not to fix this problem but you can use var api = this.api(); inside initComplete.

    In order for us to help with your search plugin please post a link to your page or a test case showing us what you have done. Also let us kwon what you are expecting the search plugin to do.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • ChazyChazy Posts: 4Questions: 2Answers: 0
    edited July 2020

    Yeah, I completely forgot about this.api(). Now I can call draw(). Thanks.

This discussion has been closed.