search plug-in to enhance searching
search plug-in to enhance searching
I am still pretty new to datatables, and I need to enhance the search capability for my application.
I have read the page at https://datatables.net/manual/plug-ins/search, and it looks doable to me, but I wanted to make sure this is the right direction to go.
Right now I have some cells in my table that are just text data, and of course the search function works for those cells.
Other cells, however, have a table in them holding several rows of text. Would I be able to create a plug-in that drilled down into searchData, picked apart the tables in cells, if present, and return true or false according to what is there?
This looks like the right approach, but I thought I would ask first.
Also, if someone here has already done something similar, I would love to look at the plug-in.
This question has an accepted answers - jump to answer
Answers
So you have cells that have other tables within them? Are they datatables or just tables?
And that would work just fine, you can make a plugin to do anything, as long as you can code it.
However, if you dont care which row/cell youre matching within the sub-table, i think the normal search would work just fine... have you tried it?
Agreed - the host DataTable won't do anything with the sub-tables, so if you want them to be updated, that would need to be coded into your search.
I'm not aware of any existing public code that does exactly what you describe.
Allan
They are just plain tables embedded in the cells. I tried the search functionality very early on and it seemed like it was not matching on contents in them, but something else in my config could have been off. So, jLinux, I don't care what row in the embedded table matches. However, Allan says the search won't do anything with the embedded tables, so it sounds like a plugin that breaks it down is the way to go. Now that I think about it, I will just implement the search plugin, put a simple version of one of my tables up, drop into the debugger and have a look around :-)
http://live.datatables.net/gisigoke/1/edit?html,js,output
No plugin needed
Thanks jLinux, I was about to post that it was working by default.
I do have a couple of plugin questions on my mind while I am at it though.
In the search plugin example, I see two different implementations on these pages:
https://datatables.net/manual/plug-ins/search
https://datatables.net/examples/plug-ins/range_filtering.html
These two interfaces look like this (inside the identical search push):
function( settings, searchData, index, rowData, counter )
and
function( settings, data, dataIndex )
When I tried them with a trivial implementation, they both worked, and I didn't have to do anything. I am guessing that these are two of possibly many interfaces to choose from?
Apologies if this belongs in a more basic area. Happy to close this here and move it if appropriate.
Area is fine buddy.
The 2nd link just looks like it has more options/parameters available, but they both basically do the same thing...
Are you looking to filter number ranges? Thats what the plugin is for.
That plugin isn't really meant to be a fully fledged supported plugin to be widely used, its more just to show how to create your own plugins (Atleast thats what I get from it). But people do use it
Is there anything else I can help you with?
Yeah, I understood that these were just examples. I was unclear on how this plugin architecture worked. I see two examples of function calls with two different sets of parameters, and wondered how, in the plugin architecture, the parameters were arrived at for these examples. In other words, where do the values come from? Meaning, how does datatables know what to provide to these parms at runtime? Is there a set of standard function interfaces for the plugin developer to choose from? I am just starting to look into the plugins API, since that may answer this general question better than examples do.
The parameters passed into the search function are defined in the plug-ins manual.
The range filtering example doesn't need the last two parameters (actually it doesn't need the third either looking at it...) so I just having put them into the function. Javascript accepts that and just doesn't make the passed in arguments available in the function.
The API reference is the best place to got if you are implementing your own.
Allan
OK, thanks Allan, that makes sense to me now.