Why does the iDataSort property exist?
Why does the iDataSort property exist?
jnthnlstr
Posts: 27Questions: 0Answers: 0
Hello,
I have found that I want DataTables to allow the aoColumns array to be in a different order to the aoData array. This is because I have integrated DataTables with a library that provides column re-ordering functionality, and my integration point is to re-order the aoColumns array, as it appears that this is all I have to do to keep the table functional.
The one exception is the sorting function, where re-ordering the aoColumns array causes sort function to pick an inappropriate column when looking for an sType, so you can end up trying to sort string data as numeric data, or some similar problem.
The reason for this is the following two lines (3098, 3099):
[code]
iDataSort = oSettings.aoColumns[ aaSort[i][0] ].iDataSort;
iDataType = oSettings.aoColumns[ iDataSort ].sType;
[/code]
I have altered these to read:
[code]
iDataSort = oSettings.aoColumns[ aaSort[i][0] ].iDataSort;
iDataType = oSettings.aoColumns[ aaSort[i][0] ].sType;
[/code]
The same substitution is necessary at line 3105.
Things seem to work for me, I don't know if this is a safe patch, because I do not know why the iDataSort parameter exists on a column, when it seems as though this parameter is identical to the column's index in the aoColumns array.
I would appreciate clarification on why the iDataSort property exists.
Thanks,
J.
I have found that I want DataTables to allow the aoColumns array to be in a different order to the aoData array. This is because I have integrated DataTables with a library that provides column re-ordering functionality, and my integration point is to re-order the aoColumns array, as it appears that this is all I have to do to keep the table functional.
The one exception is the sorting function, where re-ordering the aoColumns array causes sort function to pick an inappropriate column when looking for an sType, so you can end up trying to sort string data as numeric data, or some similar problem.
The reason for this is the following two lines (3098, 3099):
[code]
iDataSort = oSettings.aoColumns[ aaSort[i][0] ].iDataSort;
iDataType = oSettings.aoColumns[ iDataSort ].sType;
[/code]
I have altered these to read:
[code]
iDataSort = oSettings.aoColumns[ aaSort[i][0] ].iDataSort;
iDataType = oSettings.aoColumns[ aaSort[i][0] ].sType;
[/code]
The same substitution is necessary at line 3105.
Things seem to work for me, I don't know if this is a safe patch, because I do not know why the iDataSort parameter exists on a column, when it seems as though this parameter is identical to the column's index in the aoColumns array.
I would appreciate clarification on why the iDataSort property exists.
Thanks,
J.
This discussion has been closed.
Replies
The iDataSort property is used for cases where you want one column to be sorted by the data contained in another column. This second column, will typically be hidden, although that's not necessary. If you do a search on the forum for iDataSort, there are a number of cases where this has proven to be exactly what developers are looking for - for whatever reason :-)
So going back to your main issue - changing the order of aoColumn. This is actually fairly tricky to do in DataTables. The basic idea is simple enough, change aoColumns, the informaiton in aoData[]._aData, and the TD nodes in aoData[].nTr. But there are a lot of other considerations such as header/footer and hidden columns. When I've had the change here and there, I've been working on a plug-in to change the column orders. For the most part it's working, but falling over on the hidden columns at the moment. Need to sit down and work out the logic for it sometime :-)
Regards,
Allan
Thanks for your rapid response and explanation!
If you're in the process of working on a plugin to re-order columns, please let me say that I am another source of demand - it is not ideal having to integrate another plugin to do this. Looking forward to the release... ;)
J.
I'll try and bump it up the old priority list a bit :-)
Allan