DataTables / DataTablesSrc

DataTables source repository
https://datatables.net
MIT License
628 stars 423 forks source link

Feature request: Columns should be searchable via the API, even if they were disabled during DataTable initialization #210

Open MisterVector opened 2 years ago

MisterVector commented 2 years ago

Currently, attempting to search a column via the API when searching on that column has been disabled does not return anything. I'm posting this feature request because I think that some columns may not be appropriate to search on via the search field, however through one or more filters after a search, such a column ought to be searched on. I'll try to clarify with a proof of concept.

To play around with this POC yourself, I have provided the following gists:

eligibleEmployees.html: https://gist.github.com/MisterVector/6cbbb74b74d5af7556472ec8681a5b64 eligibleEmployees.js: https://gist.github.com/MisterVector/d8b7a6c3f7b02bfce2d268c86a720ea8

The POC starts off with this table:

image

Scenario 1 below illustrates my point that some columns aren't appropriate to search on:

image

Scenario 2 shows the "Show only employees eligible for promotion" option checked, which shows only the employees eligible for promotion:

image

With the "Disable third column for search?" item checked, scenario 3 shows that performing the same search will not show any results, as that column has been disabled:

image

For scenario 4, both checkboxes have been checked, which disables the third column for search and performs a search on that column using the API, which turns up no results:

image

I'm suggesting that scenario 4 should show the intended results, regardless if the searching capabilities of that column are disabled or not.

This probably makes more sense if the column was hidden. You would disable it at initialization to make sure the hidden column is not selected when searching but then perform a search on that column using the API.

AllanJard commented 2 years ago

Yes, rather than just being a boolean option, it might be nice to allow it to be searchable: 'api'.

It isn't something I'm going to be adding soon though I'm afraid. This is the first request I can recall for this and it isn't something I've required myself yet. Will leave open for future thought.

MisterVector commented 2 years ago

I brought this up because I spent several hours one day at work trying to figure out what was wrong with my code, only to realize towards the end (after going through 2 other developers) that I had set one of the columns to disabled, but also that column was being searched via the API.

MisterVector commented 1 year ago

@AllanJard I've been working on a PR to address this issue. However, I noticed something interesting and would like your input.

I noticed that sometime back there was a change to the core.filter.js file adding an oInput.return argument when calling the _fnFilter() function:

image

However there is no such parameter in the _fnFilter() function. Here is its current signature:

image

Would you like me to remove the argument oInput.return in this PR or make a separate PR removing it? What do you see is the best path forward?

AllanJard commented 1 year ago

Good spotting! I've gone ahead and fixed that, as it is just wrong. Thanks for letting me know!