How to repopulate manually and keeping sorting?

How to repopulate manually and keeping sorting?

TxSeeltaTxSeelta Posts: 4Questions: 2Answers: 0
edited June 2014 in Free community support

I use DataTables on an existing table (which I repopulate with my own logic) to get sorting and scrolling. All works fine, I put bRetrieve to true to enable the reinitialization of the table, as to avoid the error message about being unable to reinstantiate an already instantiated datatable. However, after I empty and repopulate tbody, the sorting goes missing.

is there any DataTables.Calibrate/Reset/Recalculate or something I could use? Or do I need to hack my way around it if I don't want to use DataTable infrastructure to repopulate the table?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    However, after I empty and repopulate tbody, the sorting goes missing.

    Sounds like the append FAQ. In short, use the API to manipulate the table.

    Allan

  • TxSeeltaTxSeelta Posts: 4Questions: 2Answers: 0

    Thank you for the answer to the question.

    I'm curious though, wouldn't it be more developer friendly to have that option that I'm asking about? DataTables is obviously an augmentation for a table, thus it could easily be seen a layer above a table that changes it's projection in regards to interface and layout.

    But if the usage of DataTables requires us, after initialization, to use the DT API even for changing the basic generic layer of the table, doesn't this come with some drawbacks that could have been avoided taking another design approach of the DT layer?

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin
    Answer ✓

    wouldn't it be more developer friendly to have that option that I'm asking about?

    For certain. And if there was an API that was cross platform and cross browser will provided that information I'd jump at it. However, the DOM mutation API is very immature and not at all well supported in older browsers (which I still have to support) - see caniuse.

    doesn't this come with some drawbacks that could have been avoided taking another design approach of the DT layer?

    Almost certainly. Every single design decision has some benefits and some drawbacks. In this case, the benefit was that it works across just about every browser ever, and can be done very efficiently. Using DOM mutation just wasn't possible back when DataTables was first created (since it didn't exist) and is still impractical today since DataTables needs to support a wide range of browsers.

    I do plan to write a blog post about using DOM mutation events with DataTables in future, but for the moment, I'd suggest using the DataTables API in the same way that you have to use the jQuery API to get the most from jQuery.

    Allan

This discussion has been closed.