How to force SearchPanes columns to be displayed (and also after making them visible)

How to force SearchPanes columns to be displayed (and also after making them visible)

sloloslolo Posts: 75Questions: 15Answers: 1

Link to test case: https://live.datatables.net/xicirote/1/edit
Debugger code (debug.datatables.net): NA
Error messages shown: NA
Description of problem: Hello,

I would like to know if it is possible to force the display of all columns of the "searchPanes" component without having to set the "threshold" option: 1

Especially since it is mentioned in the documentation that it is not recommended.

If you want to force specific panes to always be present, or to always be hidden, use the columns.searchPanes.show option. This is a much cleaner way of forcing panes to show/hide.

I have seen this example https://datatables.net/reference/option/columns.searchPanes.show and try to make it works but with targets: [-1] but without success.

My test case is almost functional, I'm sure there's not much missing for it to work.


Also, when a column is invisible when generating the Datatable and then makes the column visible, this "new" column does not appear in the "searchBuilder" and "searchPanes" components.
Is this normal?


I know this post is a bit of a follow-up to the one below, but the question is slightly different, so I decided to open a new question.
https://datatables.net/forums/discussion/80822/how-to-exclude-columns-for-searchbuilder

Thanks in advance for your help and have a nice day.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,913Questions: 26Answers: 5,063
    Answer ✓

    See this example.

    Add something like this to columnDefs:

          {
            targets: ':not(.no-col-extended-search)',
            searchPanes: {
              show: true
            }
          },
    

    And remove "threshold": 1, from the buttons config. Updated test case:
    https://live.datatables.net/xicirote/2/edit

    Kevin

  • sloloslolo Posts: 75Questions: 15Answers: 1

    Hello @kthorngren,

    Thanks a lot for your answer, it works very well.

    I don't know why I didn't think to use a class instead of an array for the "target" property.

    Otherwise, do you have an idea for this question?

    Also, when a column is invisible when generating the Datatable and then makes the column visible, this "new" column does not appear in the "searchBuilder" and "searchPanes" components.
    Is this normal?

  • kthorngrenkthorngren Posts: 21,913Questions: 26Answers: 5,063
    edited April 16

    The test case shows SearchPanes is updated when column visibility changes. I think searchPanes.columns is executed each time the SearchPanes button is clicked.

    However I think searchBuilder.columns is only executed the first time the SearchBuilder button is clicked. The only option I can think of is to use /searchBuilder.rebuild() to rebuild the SearchBuilder each time visibility changes using column-visibility. For example:

      oTable.on('column-visibility.dt', function (e, settings, column, state) {
        stored = oTable.searchBuilder.getDetails();
        oTable.searchBuilder.rebuild(stored);
      }); 
    

    Updated test case:
    https://live.datatables.net/xicirote/3/edit

    Kevin

  • kthorngrenkthorngren Posts: 21,913Questions: 26Answers: 5,063

    Note that you might need to manipulate the data in the stored variable, obtained from searchBuilder.getDetails(), to handle the situation where a column has a search applied but is hidden later. Since it's hidden it doesn't match the "columns": ":visible :not(.no-col-extended-search)" selector and becomes out of sync. You can see this by searching on Name then hiding Name then making visible again.

    See the output in this test case:
    https://live.datatables.net/bekupite/1/edit

    Kevin

  • sloloslolo Posts: 75Questions: 15Answers: 1

    Really nice, it works well for searchBuilder :)

    I try this for searchPanes:

    oTable.searchPanes.rebuildPane(column);
    

    This works to show the column when it is displayed, but I can't hide it if I change its visibility again.

    Any idea please?

  • kthorngrenkthorngren Posts: 21,913Questions: 26Answers: 5,063

    Possibly you can remove the SearchBuilder searched columns from the column visibility list, using a classname, so they can't be hidden.

    Kevin

Sign In or Register to comment.