ColReorder doesn't reorder without reset
ColReorder doesn't reorder without reset
AllanCochrane
Posts: 41Questions: 1Answers: 2
See http://jsfiddle.net/ZF6S2/3/
Extra info printed in console.
It works if fnReset() is called, but that shouldn't be needed, surely?
As it happens, in my application, even when I do call fnReset(), the order is still incorrect, but I can't reproduce that just yet ...
Extra info printed in console.
It works if fnReset() is called, but that shouldn't be needed, surely?
As it happens, in my application, even when I do call fnReset(), the order is still incorrect, but I can't reproduce that just yet ...
This discussion has been closed.
Replies
Just remove the `R` option in sDom and it appears to work okay: http://jsfiddle.net/ZF6S2/4/ .
Allan
It was unclear to me just how we should use the ColReorder API. From the example on: http://next.datatables.net/extensions/colreorder/api I see:
[code]
// Swap the first and second columns
$.fn.dataTable.ColReorder( dataTable ).fnOrder( [1, 0, 2, 3, 4] );
[/code]
which gave me the impression that I had to pass in the table to apply the order.
But, having seen that there's a colReorder object available when you initialize with DataTable() and not dataTable() (aaagh!) I still say that there's a problem:
http://jsfiddle.net/aBUH7/5/
I think that I'm no longer creating a duplicate colReorder object this time.
I'm afraid i'm not seeing a problem when creating the table with `dataTable()` : http://jsfiddle.net/aBUH7/6/
Allan
Allan
Chrome:
[code]
Uncaught TypeError: Cannot call method 'order' of undefined
[/code]
FireFox:
[code]
TypeError: table.colReorder is undefined
var origOrder = table.colReorder.order();
[/code]
I believe that's correct since dataTable() returns a jQuery object, whereas DataTable() returns an API object.
I cannot explain why I was seeing dataTable() work OK in my comment above. I suspect I just looked at the resulting table and not the console log.
To summarise:
1. DataTable() doesn't work for me without a reset() call
2. dataTable() has no order() function so the example code is broken for this case
Allan
The `order()` and `reset()` methods are extensions of the DataTables 1.10 API. So yes, absolutely they will not be available when you use `dataTable()` , since, as you say, that is a jQuery instance, and not a DataTables API instance.
This is the relevant part of the code: https://github.com/DataTables/ColReorder/blob/master/js/dataTables.colReorder.js#L1272
> 2. dataTable() has no order() function so the example code is broken for this case
Can you link me to that example so I can correct it?
*Edit - do you mean this example: http://next.datatables.net/release-datatables/extensions/ColReorder/examples/reset.html ?
If you change the `DataTable()` to `dataTable()` then yes, obviously it would break, since you are changing the code to have different behaviour.
Allan
But I still have the the problem that when I use DataTable() to initialise and order() to impose an order on the columns then the re-ordering does not occur as I would expect.
The example in the jsfiddle http://jsfiddle.net/aBUH7/7/ shows that applying the columns orders:
[7,6,5,4,3,2,1,0] => ok, get [7, 6, 5, 4, 3, 2, 1, 0]
[0, 4, 3, 2, 1, 5, 6, 7] => not ok, get [7, 3, 4, 5, 6, 2, 1, 0]
[0,1,2,3,4,5,6,7] => not ok, get [7, 3, 4, 5, 6, 2, 1, 0]
This is all shown in the console.
If we add a call to reset() before each call to order() then the column ordering is applied as expected.
Now I don't believe I should have to call reset() before applying a new column order. This is the bug I'm reporting. It may be a documentation bug or it may be a code bug.
(A side issue is that in my application even if I *do* use reset() before order() the columns are still not put into the correct order but I haven't managed to write an isolated test case for that)
I don't immediately see what is going wrong, so I'll need to spend a but of time an figure fit out when I get a chance.
Allan