Filtering table based on a click
Filtering table based on a click
jjp125
Posts: 6Questions: 2Answers: 0
I am listing different categories(actually the # results for each category) on the top of my page that is data in one of the columns and then I initialize my table. If the user clicks on one of those numbers what is the best way to "filter" the table.
I am doing this with live data that I can't post so I am not exactly sure how to post it in test tables.
Answers
There are some Ajax templates you can start from here if they help for a test case. The test case doesn't need to have your specific data. The goal is to show an example of what you are trying to do.
Here are some examples that may help give you an idea of how to use
search()
,column().search()
or search plugins with your inputs:https://datatables.net/examples/api/multi_filter.html
https://datatables.net/examples/api/multi_filter_select.html
https://datatables.net/examples/api/regex.html
https://datatables.net/examples/plug-ins/range_filtering.html
If you are wanting to fetch the data from ajax based on the filter you can do something like this example:
https://datatables.net/examples/server_side/custom_vars.html
You don't need server side processing enabled to send search values via the
ajax.data
option.You can see there are lots of options. If these don't help please provide more details of how you would like the filter process to work. Maybe one of us has an example of what you are trying to do. Or we'll help you with getting the test case running if you have questions. And once running help guide you to your solution.
Kevin
Kevin,
Thanks for some direction. I will take a look at those and then see maybe putting something is test tables if I need more help.
Kevin,
Is there way to search a column based on column name and not the index number?
I am trying the code below thinking it will search the "Status" column for the text "Cancelled". Am I not understanding the documentation correctly?
table.columns( '.Status' ).search( 'Cancelled' ).draw();
The options you can pass into
column()
orcolumns()
to choose the column(s) are documented in thecolumn-selector
docs. The selector'.Status'
is looking for theth
to have the classnameStatus
to be assigned. If the header title isStatus
then maybe use':contains(Status)'
will work. Look at the string examples.If you still need help please provide a link to your page or a test case replicating the problem so we can see what you are doing.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Kevin,
Thanks for the help. I was able to get it partially working. I have it partially working from another example that was up on a test table. (http://live.datatables.net/foladewa/). The issue I am having is I have a variable set with comma separated words. I thought I read that they needed to be separated with pipes(|), however when I try that I still don't get the correct results. I just get the first set of search words I am looking for.
My test table can be found here: http://live.datatables.net/simaweke
Looks like you are missing the
g
for global match, for example:.replace(/,/g, '|');
. Updated test case:http://live.datatables.net/simaweke/2/edit
Kevin
Kevin,
OMG, that's it! That worked! Thanks so much!