2

I have two hidden columns in jQuery - BootGrid table and I don't want to show it, but I want to search by these two columns in searcher. How can I do it? I tried to add data-visible="false" data-searchable="true" data-identifier="true" but that does not work.

user353gre3
  • 2,747
  • 4
  • 24
  • 27
XXX
  • 21
  • 3

1 Answers1

1

The way Bootgrid works at the moment (version 1.3.1), it only searches for visible columns, look at their source code here:

jquery.bootgrid.js

for (var i = 0; i < that.columns.length; i++)
{
    column = that.columns[i];
    if (column.searchable && column.visible &&
        column.converter.to(row[column.id]).search(searchPattern) > -1)
    {
        return true;
    }
}

Which is strange in my opinion. I think they should make by default a column not to be searchable when it's hidden, but if the developer explicitly set it to be searchable, it should be (even for hidden columns).

One option to solve this, is changing it to be like this:

for (var i = 0; i < that.columns.length; i++)
{
    column = that.columns[i];
    if (column.searchable && row[column.id])
        if(column.converter.to(row[column.id]).search(searchPattern) > -1) {
        return true;
    }
}

This will make hidden columns to be searched. If you have any other hidden fields you really didn't want to be searchable, now you have to explicitly set searchable to false (either via html data attributes or jquery).

Moreover, if you want to use the minified version, you should minify it by yourself, since the existing one won't have these changes. Also, be careful if you or someone in your team decides to download the library again (for example for updating or some other reason).


As a bonus, you may note I also inserted a && row[column.id] to avoid exceptions when you have null values loaded via the append method.

Alisson Reinaldo Silva
  • 10,009
  • 5
  • 65
  • 83