deferRender - Render missing nodes dynamically

deferRender - Render missing nodes dynamically

lpenadiazlpenadiaz Posts: 6Questions: 2Answers: 0

Basically, this is just an updated question to this thread: https://datatables.net/forums/discussion/14443/render-after-deferrender

I have almost the same need. I'm using deferRender to speed up the loading time, but if the user clicks a button, I need to be able to generate all missing nodes so I can loop through them using .rows().nodes(). Is there any way to make this happen?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    Is there something special in the .rows().nodes() that wouldn't be in the original data retrieved?

    Maybe you can loop through the original data to get or set the information needed.

    Please provide more specifics of what you want to do. Maybe someone can give you some ideas.

    Kevin

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    At the moment the only way to get DataTables to generate the "missing" nodes is to have it draw them on screen. There isn't (currently) an API to have it generate rows on demand, other than to have them displayed and then draw the table.

    Allan

  • lpenadiazlpenadiaz Posts: 6Questions: 2Answers: 0

    Thanks for your replies.

    @kthorngren, yes. I'm using columnDefs to format the result. Also, I'm using the same result set (from ajax) in multiple pages with different Datatables initialization (which decide what and how should be displayed). This logic highly changes the actual data stored in .rows().data(). I could implement the same logic while looping through the data, but then the code will be harder to maintain (since we'll have the conditions and formatting in two places instead of one).

    @allan, I understand. But maybe you could point me to somewhere to have an idea on how to code a workaround to make it happen? In the thread mentioned in my question, you referenced the code in the old TableTools extension, but the code is no longer available.

    Either way, thank you both for your answers.

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    Answer ✓

    This is where DataTables does it internally on draw.

    So what you could do is have an API plug-in which will do it. In fact, here it is as calling the internal methods isn't obvious (or documented since they are internal methods!):

    $.fn.dataTable.Api.register( 'rows().generate()', function () {
        return this.iterator( 'row', function ( context, index ) {
          context.oApi._fnCreateTr( context, index );
        } );
    } );
    

    http://live.datatables.net/xawepede/1/edit

    You can use row selectors with it if you only want to generate nodes for specific rows as well.

    Allan

  • lpenadiazlpenadiaz Posts: 6Questions: 2Answers: 0

    This is perfect! Exactly what I needed.

    Thanks!

This discussion has been closed.