colReorder plugin issues with column().cache() API

colReorder plugin issues with column().cache() API

vismarkvismark Posts: 79Questions: 5Answers: 0

Hi, with reference to this fiddle, it looks like the column().cache() API doesn't work anymore after a colReorder. You can try switching the first and the second column...after that the API won't return data until you redraw the table. Is there any workaround I can apply?

Replies

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    Use colReorder.transpose() to get the current index.

    Kevin

  • vismarkvismark Posts: 79Questions: 5Answers: 0

    I'm not tryin to get column index, I'm tryin to get column's data

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    The colReorder.transpose() API provides the current column index. Instead of using this for the first column:

    table.column( 0 )
    

    Use this to get the reordered index of the first column:

    table.column( table.colReorder.transpose(0) )
    

    See this example:
    http://live.datatables.net/fiyugequ/1/edit

    Move the columns and you will always see the data from the Name column no matter where it is placed.

    Kevin

  • vismarkvismark Posts: 79Questions: 5Answers: 0

    Thanks Kevin, I know this but it has nothing to do with what I'm saying.
    If you take a look at the example you can see that I've explicitly targeted column 0 before colReorder and column 1 after colReorder to simplify the situation...and the API is not working on ANY column index I may target...so your solution has nothing to do with that problem I'm in. Please try the fiddle...

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954
    edited January 2023

    Sorry, misunderstood the question. The column().cache() states this:

    Cached data is not guaranteed to be available at any particular moment. If DataTables hasn't requested the data, it won't have been cached.

    I don't know the internals of Datatables but it seems like reordering the columns clears the search cache. I added dt.draw( false ); to the event handler and the cache is populated so the API works.
    https://jsfiddle.net/htuqj3dn/

    Please describe what you are trying to do see we can offer suggestions.

    Kevin

Sign In or Register to comment.