Test if a column is searchable

Test if a column is searchable

yshtilyshtil Posts: 17Questions: 6Answers: 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

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    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.

    Colin

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 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.

    Allan

  • yshtilyshtil Posts: 17Questions: 6Answers: 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: 20,309Questions: 26Answers: 4,769

    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.

    Kevin

Sign In or Register to comment.