Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column choice to searchPanes example #242

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AdamRJensen
Copy link

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.

@mwouts
Copy link
Owner

mwouts commented Mar 20, 2024

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 ?

@AdamRJensen
Copy link
Author

AdamRJensen commented Mar 21, 2024

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]}

@mwouts mwouts added this to the 2.0.1 milestone Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants