Filtering each column programmatically
Filtering each column programmatically
Hi!
To begin, I want to thank you for your beautiful plugin, such great work!
In my current DataTables setup, I can show/hide columns (ColVis), reorder them, sort them.
I even coded a "scenario" function that does changes to the table according to the "data-*" attributes of the element clicked.
See this example of a scenario configuration to have an idea of what I'm talking about :
<li data-colums-show="0,1,2,3" data-colums-hide="4,5,6,7,8,9" data-columns-order="9,8,7,6,5,4,3,2,1,0" data-columns-sort-asc="0,1,2" data-columns-sort-desc="3">
<a role="menuitem" href="#">Scenario 1</a>
</li>
Now what I would like to add, is the possibility when loading a scenario, to only show the rows where (for example) the value of a specific column is greater than 20, or another column is lower than 70%.
I have tried to use "fnFilter" but the function parameter is a string, so I can't compare the values : greater than / lower than.
I have tried "$.fn.dataTable.ext.search.push" and returning a boolean : This works but is not column specific + when the order of the columns changes, I cannot find the right data to compare anymore. data[n] does not contain the same values as before sorting anymore, unfortunately.
Do you have any ideas that could help me implement this functionality?
If can't show you the table right now. I'll try to make a basic example if we don't manage to find any directions or functions to use.
Thanks in advance for your help,
Tim
This question has accepted answers - jump to:
Answers
You have to use
$.fn.dataTable.ext.search
as you suggestion if you want to perform complex matching such as ranges. You would need one filter for each column potentially. Not ideal I know, but that is currently the only option.Allan
Now that is a quick reply !
I will probably manage to achieve what I want with that function. I wanted to know if I had missed the magical one in the documentation somehow, but apparently not. :)
Thanks a lot allan !
Filtering is in bad need of an overhaul in DataTables. 1.11 will see that!
Allan
yadcf
:)
Thanks daniel_r!
I am going to use your plugin, seems perfect for my needs.
Though, I have a question concerning the
exFilterColumn
API function.Is it possible to call the function with {from: 20, to: 'max'} or something similar, when the user only wants a minimum or maximum value and not both ?
Thanks!
You are welcome,
It should work. try
{from: 20'}
or{from: 20, to: ''}
, also see docs regarding this apiHi daniel_r,
Seems like (at least with a
filter_type: "range_number_slider"
), it does not work to set{from: 20, to: ''}
or to simply set{from: 20'}
The 'to' value of the slider becomes 'NaN' and makes it impossible to sort correctly.
I am using the latest beta of your plugin.
Not a big issue as it selects the maximum value when setting a big number, but still a small bug. Example :
{from: 12,to:99999}
just sets the slider's max value. ;)Thanks !
@Cymo , You are right, its a bug indeed , feel free to open an issue on github