Way to Manually Specify Column Type?

Way to Manually Specify Column Type?

coreyocoreyo Posts: 5Questions: 0Answers: 0
edited January 2011 in General
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 "&nbsp") 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.

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Hi coreyo,

    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
  • coreyocoreyo Posts: 5Questions: 0Answers: 0
    From what I can see of the type detection/sorting plugins, they consist only of a regular expression matcher (for the type detection), and a comparator function (for the sorting). Unless there is more to it that I'm not seeing, it does not appear to give you a way to troll down the column values looking for a non-blank entry. Is this incorrect?

    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.
This discussion has been closed.