Changing how a column sorts
Changing how a column sorts
I currently have a defined column render for a specific column like such:
"render": function (data, type, row, meta) {
return '<a href="' + getLink(data) + '">' + data[0] + </a>;
}
My issue is that the data variable is an array, such as [0, 1, "String", 1, "AnotherString", 4, "OneMoreString"] etc.
The reason the data variable is an array is that it contains properties to generate the link for the <a> element surrounding the value.
When I try to sort asc or desc on this column it always messes up and doesn't sort based on data[0], in which I want to as that is the value being displayed.
An example of data:
[0] => [4, 3, "string", 1, "string", 1, "string", 2, "string", 0, "string"]
[1] => [5, 1, "string", 1, "string", 1, "string", 1, "string", 1, "string" ]
[2] => [5, 1, "string", 1, "string", 1, "string", 1, "string", 1, "string" ]
[3] => [1, 1, "string", 0, "string", 0, "string", 0, "string", 0, "string" ]
As I'm displaying data[0], the following data is put into the table, row by row:
4, 5, 5, 1
When I sort them I'd expect to sort them as such:
1, 4, 5, 5 or 5, 5, 4, 1
But what happens is:
4, 5, 5, 1 or 1, 5, 5, 4
This question has an accepted answers - jump to answer
Answers
== Didn't mean to input answer ==
Currently, your data is the result of the render function.
So, first you need to set your data properly. There are many ways to do this job...
My suggestion is:
Not user
columns.render
, instead usecolumns.createdCell
because it will not affect the sort.so the code will be something like this:
As I said there are a variety of way to solve the problem.
Thank you, this worked perfectly