table.column.index() misleading 'toVisible' and 'fromVisible'

table.column.index() misleading 'toVisible' and 'fromVisible'

DabooDaboo Posts: 6Questions: 1Answers: 0
edited March 2014 in DataTables 1.10
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!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi,

    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
  • DabooDaboo Posts: 6Questions: 1Answers: 0
    Hi Allan, thank you for the reply.
    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.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I don't quite understand I'm afraid - you are transforming the visible index, to the visible index - which isn't going to work. When using `toVisible` DataTables assumes that the data passed in as the second argument is the data index. Its just an integer, so DataTables can't know if its the visible or data index without the first parameter.

    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
  • DabooDaboo Posts: 6Questions: 1Answers: 0
    edited March 2014
    Yes Allan, it's exactly about this broken thing that I am talking about :
    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!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Doh - yup. Completely inverted the logic for this in DataTables... Sometimes I won't how I manage to get out of bed in the morning!

    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
This discussion has been closed.