Open AdamRJensen opened 3 months ago
Oh interesting! Maybe I would consider adding another more elaborate example, possibly with custom rendering functions.
Do you know how this searchPanes.columns
field relates to e.g.
columnDefs: [
{
searchPanes: {
show: true
},
targets: [5]
}
],
I see for instance that this example has both ?
The logic behind which columns are used in the search pane is split across both columnDefs
and searchPane
(IMHO not very straightforward).
Step 1 pre-selection - The** options in columnDefs
are used to determine which columns MAY be used for the search pane (by default it's based on assessing how unique each column is): https://datatables.net/reference/option/columns.searchPanes.show
Step 2 final selection - Then** columns
option in searchPane
can then subsequently be used to specify a subset of the columns determined by the columnsDefs logic.
As an example, let's imagine a column of all ones (in practice not useful for sorting). This column would by default not be used for the search pane, because the logic in columnDefs will find it insufficiently unique. Therefore, if we tried adding it in Step 2 using 'searchPane': {'columns': [1]}
then the column would not show up because it was selected in columnDefs in Step 1. For the columns of ones to be included in the search pane, we need to manually force it to be included in the columnDefs step as such:
columnDefs=[{'searchPanes': {'show': True}, 'targets': [1]}]
Now, if you want to select which columns to use manually, then I would simply pre-select all columns in step 1 and limit the selection in step 2 (there could be some speed issues with this?):
columnDefs=[{'searchPanes': {'show': True}, 'targets': ['_all']}]
layout={searchPanes={"columns": [16,3,1]}
I think it is useful to demonstrate how to choose which columns to use for the search pane, which is done by adding the a "columns" entry to the searchPanes dictionary.