Way to Manually Specify Column Type?
Way to Manually Specify Column Type?
I am using datatables to display results from a search form. The displayed columns as well as their contents are dynamically generated as HTML (dom) then initialized with jQuery as a datatable. The problem that I am running into is that many of the values for the columns are often NULL. In this case the value of the " " placeholder is used for proper css rendering.
I noticed that, when the first entry has an empty (or " ") value, it is assumed to be a string, regardless of whether or not all non-empty values are recognizable dates. Is there a way to manually specify in the HTML (or elsewhere) when a column is supposed to be seen as a date type?
Even better, any way to change a setting or easily alter the code to keep going through the entries in a table to look for a walk down the column to find a non-empty entry before assuming that the type is STRING?
Thanks in advance for any help.
I noticed that, when the first entry has an empty (or " ") value, it is assumed to be a string, regardless of whether or not all non-empty values are recognizable dates. Is there a way to manually specify in the HTML (or elsewhere) when a column is supposed to be seen as a date type?
Even better, any way to change a setting or easily alter the code to keep going through the entries in a table to look for a walk down the column to find a non-empty entry before assuming that the type is STRING?
Thanks in advance for any help.
This discussion has been closed.
Replies
Yes indeed you can specify the type by using the sType option: http://datatables.net/usage/columns#sType . One thing to remember though is that there is a reason the auto-detected types are detected the way they are :-). For example how do you treat " " numerically? ±infinity or 0 or something else? You can create your own sorting plug-ins (and activate them with sType or an auto-detection plug=in) like these: http://datatables.net/plug-ins/sorting
Allan
In my case, the date types are in a standard format and can be sorted with no problem, so long as they are properly detected as dates. Is there a way to specify column type in an HTML attribute in the header rather upon the datatable's initialization? If not, is there a way to make a call programmatically after the table has been initialized to set the sType attribute? Been looking for an example on how to set options programmatically after initialization.