Create custom type
Create custom type
gbersac
Posts: 5Questions: 2Answers: 0
I want to create new value for the columns.type format.
For instance if I define a column
$('#' + idTable).dataTable( {
data: content,
columns: [{
"data": "rate",
"type": "percentage",
}]
});
Every time I set type to percentage, I want it to :
- call a specific render function for rendering the value (for instance multiply the value by 100 and append " %")
- call specific function for searching and sorting.
- why not automatically set specific option like searchable = false for percentage value.
How to archieve it ?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
There is no option for that via a type at the moment. You need to use
columns.render
to do that.It will. See the sorting legacy documentation (I'm still working on updating it for the new site style - but the old method still works).
I don't understand I'm afraid. Are you suggesting that the default for DataTables should be to disable searching of percentage values? I can't think of any reason that should be the default operation to be honest.
Allan
First thanks for your answer.
I am suggesting that type could be bound to specific default option.
Let's say I create a custom type image. It should be great to state that, unless specified the contrary, image are not searcheable.
I see - thanks for the clarification! To some degree that is possible already by proving a filtering plug-in for the set type - but I take your point, this is an area that could use some improvement! I've been thinking that for a while but not yet sure how to do it without breaking backwards compatibility... I'll keep thinking about it, but it could potentially fall into DataTables 2 which will break backwards compatibility (it is a way off though!).
Allan
to delete
I am thinking about something like that :
Then :
And the render and search function will authomatically be called for the column entitled rate !
This looks like a simple extension of the functionnality already provided by data tables (maybe no backward compatibility breakdown), and would be quite handy.
What do you think about it ?
It looks like a good idea - it would introduce several new code branches and indirection into the DataTables code, so I won't be implementing it immediately as it would be a lot of work. But I will certainly keep it in mind when I do get around to updating that part of the library.
Allan