Quantcast
Viewing all articles
Browse latest Browse all 82142

ColReorder + FixedColumns plugin

Hi,

I just started using Datatables.js. I have a requirement to be able to use ColReorder + FixedColumns plugins on the same table. The bug I think I've found:
- Create a datatable, my datatable has 8 columns but column count doesn't mather
- use ColumnsPlugin plugin, set the first two columns to fixed
...
"oColReorder": {
"iFixedColumns": 2
}
...
- use FixedColumns plugin, set iLeftColumns to 2
....
new FixedColumns(oTable, {
"iLeftColumns": 2,
"iLeftWidth": 264
})
....

Now if you start dragging column header:
- you cannot drag the first two columns that are fixed by the FixedColumns plugin - ok
- you cannot drag elements before/between the first two columns that are fixed by the FixedColumn plugin - ok
- you can drag the first two columns that are NOT fixed by the FixedColumns plugin - ok
Issue: you cannot drag elements to before/between the first two columns NOT fixed by the FixedColumns plugin. For example, if you would like to move the third column NOT fixed by the FixedColumns plugin to between the first and second column, you can't.
You can reproduce this bug on the demo site too:
http://datatables.net/release-datatables/extras/ColReorder/fixedcolumns.html
You cannot move the Browser column to between the index column and the Rendering engine column.

I think the problem is, that there should be to numbers: iFixedColumns: how many columns cannot be moved counted from the left.
iFixedByFixedColumnsPlugin.
...
"oColReorder": {
"iFixedColumns": 2
"iFixedByTheFixedColumnsPlugin": 2
}
...

ColReorder _fnMouseDown:

aoTargets array does not contain the columns that are fixed by the FixedColumns plugin, so those columns shouldn't be spliced.
/* Disallow columns for being reordered by drag and drop, counting left to right */
if (this.s.fixed !== 0)
{
this.s.aoTargets.splice( 0, this.s.fixed - this.s.fixedByFixedColumnsPlugin );
}

ColReorder _fnMouseMove:
when calculating this.s.mouse.toIndex is calculated based on the non fixed table indexes, to make the fnArraySwitch function work properly with, the toIndex should be added up by the this.s.fixedByFixedColumnsPlugin number:

"_fnMouseMove": function ( e )
{
.....

/* Based on the current mouse position, calculate where the insert should go */
var bSet = false;
for ( var i=1, iLen=this.s.aoTargets.length ; i<iLen ; i++ )
{
if ( e.pageX < this.s.aoTargets[i-1].x + ((this.s.aoTargets[i].x-this.s.aoTargets[i-1].x)/2) )
{
this.dom.pointer.style.left = this.s.aoTargets[i-1].x +"px";
this.s.mouse.toIndex = this.s.aoTargets[i-1].to + this.s.fixedByFixedColumnsPlugin;
bSet = true;
break;
}
}

/* The insert element wasn't positioned in the array (less than operator), so we put it at
* the end
*/
if ( !bSet )
{
this.dom.pointer.style.left = this.s.aoTargets[this.s.aoTargets.length-1].x +"px";
this.s.mouse.toIndex = this.s.aoTargets[this.s.aoTargets.length-1].to + this.s.fixedBFixedColumnsPlugin;
}
},

Could you please check if the bug above is still relevant?

Viewing all articles
Browse latest Browse all 82142

Trending Articles