ColReorder doesn't reorder without reset

ColReorder doesn't reorder without reset

AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2
edited February 2014 in Bug reports
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 ...

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    You are initialising ColReorder twice on the same table, which is confusing it. The `R` option is creating one instance, and the `new $...` is creating a second. After that, who knows what will happen!

    Just remove the `R` option in sDom and it appears to work okay: http://jsfiddle.net/ZF6S2/4/ .

    Allan
  • AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2
    That fiddle is not working for me!

    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.
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Agreed - the API examples there are complete rubbish. I'll fix that in a minute.

    I'm afraid i'm not seeing a problem when creating the table with `dataTable()` : http://jsfiddle.net/aBUH7/6/

    Allan
  • AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2
    Wierd, changing from DataTable to dataTable fixes the problem for me.
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    It should work either way! As far as I can tell, it does. Or am I wrong?
  • AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2
    dataTable() is OK, DataTable() is broken for me on http://jsfiddle.net/aBUH7/6/
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    The only thing I've changed in this fiddle is the `d` to `D` and it appears to work okay: http://jsfiddle.net/aBUH7/7/ . Are you getting any errors in the console? What browser are you using?

    Allan
  • AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2
    I tried it in FireFox (27.0.1) and Chrome (33.0.1750.117 beta-m) with http://jsfiddle.net/aBUH7/8/ in which I use dataTable(), both have the issue:

    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
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    edited February 2014
    Ah! Suddenly I realise. It is not that you can't initialise the plug-in (which I thought was the problem), but rather than the method `order()`doesn't exist when you use a `dataTable()` constructor.

    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
  • AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2
    I think we've been sidelined by the difference between the return values from dataTable() and DataTable(). I haven't spotted a documentation or example error for that.

    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)
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Got it - yes - this very much looks like a bug. Thanks for the clarification.

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