HTML Elements in Column().Data().Filter()
HTML Elements in Column().Data().Filter()
Hi all,
My question is how are html elements and number symbols (ex: -, %) in td's processed when you run column().data().filter(). I keep getting a type error when I use the following example. I think it's the html elements or the % signs next to my numbers. Not sure.
Here's my code:
var table = $("#example").DataTable();
table.column(2).data().eq(0).filter( function (value, index) { return value > 2 ? true : false } ).draw()
Here's the error I'm getting:
Uncaught TypeError: Function.prototype.apply: Arguments list has wrong type jquery.dataTables.js:6659
_Api jquery.dataTables.js:6708
_Api.eq jquery.DropDownMenuSort.js:239
(anonymous function) jquery-1.11.1.min.js:3
m.event.dispatch jquery-1.11.1.min.js:3
m.event.add.r.handle
Thanks in advance.
This question has an accepted answers - jump to answer
Answers
First of all, I doubt that
filter()
is going to do what you want here. It filters the result set - not the table!As the documentation says:
From your code above it looks like you expect to be able to search the table and draw with only value > 2 results. Currently there is no way to pass a function into
column().search()
- that is something that I will be adding for v1.11.At the moment you would need to use a search plug-in.
Allan
Thanks Allan. That's helpful, I'll give it a shot.
I'm a bit confused, however; don't both methods return a new instance of the Datatables Api? Would you provide an example of when one would use the filter method?
Thanks.
Matt
Yes, but they do different things!
will search the table for "Allan" and display only rows which have "Allan" in them.
However:
will filter the array of data (in this case from column 0) and result any result that contains "Allan" into the result Api instance (use
toArray()
to make it a real array). This does not effect the table display in any way.Allan
Ok, thanks Allan. That's very useful.