Enhancement: Index column example

Enhancement: Index column example

gyrocodegyrocode Posts: 126Questions: 6Answers: 30
edited October 2015 in Free community support

In the Index column example the code works fine.

However when used together with Buttons extension the index column doesn't get printed and doesn't appear in PDF and CSV files.

The solution is to call cell().invalidate() API method after updating the DOM.

t.on( 'order.dt search.dt', function () {
   t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
      cell.innerHTML = i + 1;
      t.cell(cell).invalidate('dom'); 
   } );
} ).draw();

I'm proposing to modify the example above and correct the code accordingly. However it may be not optimal solution in case of large datasets.

See this jsFiddle for demonstration and related discussion on Stack Overflow.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    Good point - thanks for suggesting this. Let me have a little think about it before I drop it in. I can see it could be useful, but also potentially confusing for new comers.

    Allan

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30

    Please note that I haven't tested it with large dataset, invalidating cell data on a search or sorting may not be the best idea.

    This is only needed when data is exported. So now that I think of it, it maybe not the best solution. Instead I would invalidate the data once on data export. But I can't seem to find an easy way to call invalidate before the PDF/CSV export.

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin
    Answer ✓

    That probably would be a better option. It might be best for the buttons to trigger some kind of preAction event that can be listened for and whatever updated required are triggered.

    Allan

  • gyrocodegyrocode Posts: 126Questions: 6Answers: 30
    edited October 2015

    Having preAction would be the better. Or maybe return true in action callback to proceed with default action or false to cancel default action for built-in buttons. That would be more logical and would not require extra option.

    My idea for a workaround is to use button().action() to save current action and then call this saved function after invalidation is made.

This discussion has been closed.