Changing column type on the fly?
Changing column type on the fly?
(I'm not sure if this is actually possible - either by intentional omission (because it's a little odd), or there's just no support to do it yet.)
I've got a fairly complex table, which I'm sorting using an external #SELECT element rather than column header clicks. Depending on what option is picked in the SELECT, I want a given column in the table to sort according to different comparison functions. To illustrate (badly:)
Table has 4 columns: c0,c1,c2,c3
SELECT has 8 options: op0 .. op7.
Picking a given option in the select (i.e. op1) should cause a given column (i.e. c2) to sort according to one comparison function. However, picking another option (op2) should cause the same column to sort according to a different comparison function.
How I want to achieve this (seems like the best way from the documentation but I can't make it work) is to dynamically set a new sType on the given column then call fnSort on that column, with me defining a few custom sTypes for the comparisons I need.
I can also see that this could be achieved by inserting a lot of hidden columns (about 2 for every 'real' column in my table) and sorting ASC/DESC on them. But I don't want to as it's adding a lot of duplication and page weight to the raw HTML document.
I've trawled the docs and I've found lots of bits and pieces relating to what I want to do, but can't quite see how to string it together. Any brilliant ideas would be gratefully received.
Thanks,
Chris.
I've got a fairly complex table, which I'm sorting using an external #SELECT element rather than column header clicks. Depending on what option is picked in the SELECT, I want a given column in the table to sort according to different comparison functions. To illustrate (badly:)
Table has 4 columns: c0,c1,c2,c3
SELECT has 8 options: op0 .. op7.
Picking a given option in the select (i.e. op1) should cause a given column (i.e. c2) to sort according to one comparison function. However, picking another option (op2) should cause the same column to sort according to a different comparison function.
How I want to achieve this (seems like the best way from the documentation but I can't make it work) is to dynamically set a new sType on the given column then call fnSort on that column, with me defining a few custom sTypes for the comparisons I need.
I can also see that this could be achieved by inserting a lot of hidden columns (about 2 for every 'real' column in my table) and sorting ASC/DESC on them. But I don't want to as it's adding a lot of duplication and page weight to the raw HTML document.
I've trawled the docs and I've found lots of bits and pieces relating to what I want to do, but can't quite see how to string it together. Any brilliant ideas would be gratefully received.
Thanks,
Chris.
This discussion has been closed.
Replies
ccTable.fnSettings().aoColumns[n].sType = 'newType'
Seems to set the type. However, the question now becomes - does this way lie madness?
Allan
I I have something resembling:
[code]
First kind of sort on col 1
Second kind of sort on col 1
First kind of sort on col 2
Second kind of sort on col 2
[/code]
Picking an option triggers a function which uses a lookup table to determine which column the sort belongs to i.e. something like:
[code]
var lookup = {
'type-name-1' : 0,
'type-name-2' : 0,
'type-name-3' : 1, //etc.
}
[/code]
Then I just change the column type of that column, and trigger a re-sort:
[code]
ccTable.fnSettings().aoColumns[thisCol].sType = sortType;
ccTable.fnSort([[thisCol,'asc']]);
[/code]
It's a fairly specific use-case, but hopefully this helps someone out.
Regards,
Allan