Getting column.type via API

Getting column.type via API

JammySlayerJammySlayer Posts: 43Questions: 12Answers: 2

I'd like to be able to find the type set via options within the API but can't seem to find a way of retrieving it?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    There isn't currently an API method for that I'm afraid. What's the use case?

    Allan

  • JammySlayerJammySlayer Posts: 43Questions: 12Answers: 2

    Doing basically what's said in here:
    https://datatables.net/reference/api/column().cache()

    I've noticed that it messes up the ordering for certain types, I attempted to fix it using

    options.unique().sort(jQuery.fn.dataTableExt.oSort["natural-asc"]);

    Which fixed the 1, 10, 2, 3 issue, but I've also got date's in selects, which appear 1 Feb 2017, 2 Jan 2000, 3 Mar 2018, etc

    So I figure if I can grab the type I can work out which form of sort to use on as the comparator.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Ah I see - you want to get the list of data from a column (or other data point) in the same order that DataTables would sort it based on the data type? That's something I've thought about a number of times and plan to introduce it in future.

    The only way to get the type information for a column is from the private settings store (table.settings()[0].aoColumns[i].sType). It is worth noting that the settings parameters might change in future versions (I don't currently have any plans to change that one, but who knows where development leads sometimes...).

    Allan

  • JammySlayerJammySlayer Posts: 43Questions: 12Answers: 2
    edited January 2018

    That works, thanks, be nice if there was column.type() to return that value though!

    Using :
    column.settings()[0].aoColumns[column.index()].sType

    Due to my use case of having the column

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    There is a good chance that there will be in v2!

    Allan

  • JammySlayerJammySlayer Posts: 43Questions: 12Answers: 2

    Doh, just worked out an issue, can't find auto detection namely we're using Moment for dates, so the type for the dates is number as we're passing a unix date from the back end and using render to convert it to a moment date, which we then use datetime-moment.js to do our ordering with. Am I able to leverage the same method some how, or is the resolved type available somewhere?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The resolved type is returned by the $.fn.dataTable.moment function.

    Allan

  • JammySlayerJammySlayer Posts: 43Questions: 12Answers: 2
    edited January 2018

    Worked out why it was still saying num, fell over orthogonal data, "type" wasn't being used currently in this instance.

This discussion has been closed.