Test if a column is searchable

Test if a column is searchable

yshtilyshtil Posts: 16Questions: 5Answers: 0

Here is a code fragment that changes the footer of each column into an input type search. How do I test if the relevant column is searchable and do not do it if not searchable?

    $('#usersData tfoot th').each(function () {
        var title = $(this).text();
        $(this).html('<input type="search" placeholder="Search ' + title + '" />');

The "usersData" tag is that of the relevant table.

This question has an accepted answers - jump to answer


  • colincolin Posts: 14,966Questions: 1Answers: 2,563
    Answer ✓

    There isn't an API method to determine if a column is searchable, so you'll need to remember what the original config is. each() has an index parameter that you can check against, and just return from the function is it's one that's not searchable.


  • allanallan Posts: 59,799Questions: 1Answers: 9,682 Site admin

    You aren't the first to ask about this, so I've created a little plug-in that adds an API method for this.

    You can see an example here.


  • yshtilyshtil Posts: 16Questions: 5Answers: 0

    Your plugin is written in Java, am I missing something? My understanding is that Java is a no-no on the client side.

  • kthorngrenkthorngren Posts: 19,138Questions: 26Answers: 4,536

    The link in the repo is written in Typescript. The code at the bottom, which is also used in the example, is written in Javascript. There is no Java in any of the code.


Sign In or Register to comment.