when a column made dynamically hidden, column search box works incorrectly

when a column made dynamically hidden, column search box works incorrectly

umaeswaraumaeswara Posts: 15Questions: 2Answers: 0

if we have search boxes for each column and then we make one of the column invisible the search box still linked with column which got hidden and incorrectly shows the rows which are search results of the column which got hidden. I see couple of requests 2014, 2015, 2017, for fixing this bug and Allan saying he will look into it in future. Is this bug got fixed? how can I dynamically make a ciolumn searchable/non-searchable in relation with column visible/invisible . This is giving incorrect results. please let me know if this bug got fixed?

Answers

  • umaeswaraumaeswara Posts: 15Questions: 2Answers: 0

    how can I make my datatable with search column work correctly? when I dynamically hide a column.

  • kthorngrenkthorngren Posts: 10,565Questions: 25Answers: 2,407
    edited September 17

    As Allan mentioned, in the other thread you commented in, a search plug is the best option. Thought it would be an interesting problem to try so I built an example:
    http://live.datatables.net/bisasori/1/edit

    It has the Office column hidden at initialization. Plus columns can be hidden with the Colvis button. Type lo or Lo in the search input. Only 10 rows are returned since its ignoring the Office column. You can test this by commenting the visible: false line.

    Now use Colvis button to hide the Name column. One row, Gloria Little, is removed. Unhide the column and Gloria is displayed again. The column-visibility event is used draw the table to update the filters when the visibility changes.

    Hope this gets you started with your solution.

    Kevin

  • umaeswaraumaeswara Posts: 15Questions: 2Answers: 0

    thank you very much Kevin. I am looking at your example.

  • umaeswaraumaeswara Posts: 15Questions: 2Answers: 0

    Hi Kevin, this example is giving grand search capability. can you please help to extend this to each column search box. the column search like this https://datatables.net/extensions/fixedheader/examples/options/columnFiltering.html

  • kthorngrenkthorngren Posts: 10,565Questions: 25Answers: 2,407

    This thread among others show how to incorporate column searching with hidden columns.

    Kevin

  • umaeswaraumaeswara Posts: 15Questions: 2Answers: 0

    i have used this --

    var column = $('table').dataTable().api().column($(this).val())
    let columnsettings = table.settings()[0].aoColumns[$(this).val()];
    column.visible( ! column.visible() );
    columnsettings.bSearchable = column.visible();

    this made column hidden as non-searchable. but search box lined up still got linked with previous index ; so individual search box on column still tied up previous unhidden column and it is giving incorrect results.

  • kthorngrenkthorngren Posts: 10,565Questions: 25Answers: 2,407

    Where did you use that code? Sorry, I don't understand th context of where you applied this code and what it is actually doing.

    Please provide a test case showing the issue. You can update mine if you want.

    Kevin

  • kthorngrenkthorngren Posts: 10,565Questions: 25Answers: 2,407

    I copied the code from the example you linked to:
    https://datatables.net/extensions/fixedheader/examples/options/columnFiltering.html

    Into my example and it seems to work as is:
    http://live.datatables.net/zoxucoku/1/edit

    Please update the example to show the issue you are having.

    Kevin

Sign In or Register to comment.