Orthogonal data: Just use the 'data' property

Orthogonal data: Just use the 'data' property

fsldfsld Posts: 4Questions: 2Answers: 0
edited April 2015 in Free community support

if I have a columns object defined like this:

{
data: 'height',
type: 'num-fmt'
}

And then I add a columnDefs object for it like this:

{
targets: [14],
render: {
 display: function(d) { return 'Approx. ' + d + ' meters'; },
 sort: height,
 }
}

I'll get an error for the sort property, because DT will try to look for height.height (or height[i].height?). DT expects several differently-formatted values under the same property in the data, but that isn't always the case. Is there a way to tell it to just use same data as the columns definition -> data property?

Or is this the only way:

sort: function(d) {
    return +d;
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Answer ✓

    because DT will try to look for height.height (or height[i].height?)

    It depends upon what is in the variable height.

    Is there a way to tell it to just use same data as the columns definition -> data property?

    Set the _ property of the render object to null. Then the data will be used unless there is an override given.

    Allan

  • fsldfsld Posts: 4Questions: 2Answers: 0

    Cool, I thought there might be something like that in there but I couldn't find it in the docs. (I didn't really know what to search for).

    Thanks again, Allan!

This discussion has been closed.