ColReorder breaks ColVis's exclude and restore functionality
ColReorder breaks ColVis's exclude and restore functionality
richardp
Posts: 10Questions: 0Answers: 0
When using ColReorder to change the order of columns, it messes up ColVis due to its storing indices instead of column names. This affects exclusion (aiExclude option) but also restoring original visibility (via the internal aiOriginal).
The exclude part was fixed by stefan (http://datatables.net/forums/discussion/comment/15964#Comment_15964) although I have tweaked it a little to refer to columns by mDataProp instead of sTitle. Additionally, I have changed the aiExclude option to asExclude since it now takes an array of strings. Another benefit of this is that the exclude parameter is now independent of column order and indices.
[code]
"_fnAddButtons": function ()
{
var
// ...
sExclude = "|"+this.s.asExclude.join('|')+"|";
for ( var i=0, iLen=this.s.dt.aoColumns.length ; i
The exclude part was fixed by stefan (http://datatables.net/forums/discussion/comment/15964#Comment_15964) although I have tweaked it a little to refer to columns by mDataProp instead of sTitle. Additionally, I have changed the aiExclude option to asExclude since it now takes an array of strings. Another benefit of this is that the exclude parameter is now independent of column order and indices.
[code]
"_fnAddButtons": function ()
{
var
// ...
sExclude = "|"+this.s.asExclude.join('|')+"|";
for ( var i=0, iLen=this.s.dt.aoColumns.length ; i
This discussion has been closed.
Replies
[code]
this.s = {
// ...
/**
* Restore button resets ColReorder's column order too
* @property bRestoreColOrder
* @type Boolean
* @default false
*/
"bRestoreColOrder": false,
// ...
}
// ...
"_fnApplyCustomisation": function ()
{
// ...
if ( typeof oConfig.bRestoreColOrder != 'undefined' )
{
this.s.bRestoreColOrder = oConfig.bRestoreColOrder;
}
// ...
},
[/code]
And then update the restore button's click event:
[code]
"_fnDomRestoreButton": function ()
{
// ...
$(nButton).click( function (e) {
// ColReorder triggers a refresh of ColVis's buttons but they don't get restyled
// until the next time it is shown so it will look ugly if not hidden now
that._fnCollectionHide();
for ( var i=0, iLen=that.s.dt.aoColumns.length ; i
Allan
For now, what I think would work is simply initialising the ColReorder plug-in after ColVis, since ColReorder will store the state in the original column order, when when ColVis is initialised first, it will get the order expected and ColReorder can shunt the values around as needed after that.
I'll keep my thinking cap on about how to make this a lot more flexible though! It could be that an "original order" index gets added to DataTables core.
Regards,
Allan
Something like this perhaps? (untested)
[code]
"_fnAddButtons": function ()
{
// Populate asExclude from aiExclude using current column order
if (this.s.aiExclude.length && !this.s.asExclude.length)
for (var i=0; i < this.s.aiExclude.length; i++)
this.s.asExclude[i] = this.s.dt.aoColumns[this.s.aiExclude[i]].mDataProp;
// ...
}
[/code]
Allan