table.column.index() misleading 'toVisible' and 'fromVisible'
table.column.index() misleading 'toVisible' and 'fromVisible'
Daboo
Posts: 6Questions: 1Answers: 0
After some time playing with the column API, I discovered that toVisible and fromVisible have a respectively inverted behavior.
documentation at http://next.datatables.net/reference/api/column.index()
[code]
// var table = ......
$('#mytable th').each(function(){
var visibleIndex = $(this).index();
var dataIndex = table.column.index( 'toVisible', visibleIndex );
console.log(visibleIndex, dataIndex);
// you can play a bit with ColVis to check values
})
[/code]
Am I mistaking something?
BTW, thank you for taking DataTables to another level!
documentation at http://next.datatables.net/reference/api/column.index()
[code]
// var table = ......
$('#mytable th').each(function(){
var visibleIndex = $(this).index();
var dataIndex = table.column.index( 'toVisible', visibleIndex );
console.log(visibleIndex, dataIndex);
// you can play a bit with ColVis to check values
})
[/code]
Am I mistaking something?
BTW, thank you for taking DataTables to another level!
This discussion has been closed.
Replies
The `toVisible` option is the same as `fromData` (really its 'convert from data to visible', but less verbose) and `fromVisible` is the same as `toData` (again its really 'convert from visible to data').
In your code above, `$(this).index() is giving your the visible index (as the variable name suggests). So why would you want to convert a visible index to a visible index?
Allan
The whole point of my post was to demonstrate that "toVisible" actually returns the dataIndex, and not the visible index.
I will double check my code and the DataTable index() function to be sure that issue is in the API and not on my side.
So int he above code, DataTables thinks you are passing in the data index to be transformed - which is why it is breaking.
Or have I misunderstood?
Having said that, there is something a bit broken here: http://live.datatables.net/yehumuc/1/edit . Not sure what, but I'll look into it on Monday morning!
Allan
in your exemple at http://live.datatables.net/yehumuc/1/edit
if you write [code]var dataIdx = table.column.index('toVisible',visIdx)[/code] it works, returning the actual DATA index, even though we wrote 'toVisible'.
That's why I posted in the first place.
And my code was broken when I did use 'fromVisible'. When I switched to 'toVisible', everything worked as expected (hence the topic's name "misleading 'toVisible' and 'fromVisible'").
Thanks for your time!
The fix is committed here: https://github.com/DataTables/DataTablesSrc/commit/824641df . I'll sync it across to the build repo shortly.
Thanks for bring this up!!!
Allan