New API methods

New API methods

sronsieksronsiek Posts: 52Questions: 11Answers: 0
edited October 2014 in Free community support

In general, I'd like to say that the new API is great - though I sometimes struggle to find the new API equivalents for things I have already implemented.

Thus data() appears to be the equivalent to fnGetData(), and I am assuming that all the old functions have a new equivalent.

I currently need to update data in a hidden column (col 0), and the data changes need to be reflected for searching.
The only way I could find is to use fnUpdate(), in a clumsy mix of old & new API:

var indeces  = oTable.api().rows().indexes()

for ( var i=0; i<indeces.length; i++ )
{
    var row_data = oTable.api().row( indeces[i] ).data()

    if ( row_data[0] != new_cell_data )
      oTable.fnUpdate( new_cell_data, indeces[i], 0, false, false )
}

oTable.api().draw()

Could you suggest a cleaner soln - perhaps using new API instead of fnUpdate?

A side-effect of fnUpdate seems to be that it destroys existing event bindings on
all cells of the updated row. Is this avoidable?

What would be great is a sort of cheat - sheet, a 2 col table giving equivalents of common tasks in new & old APIs.

Replies

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
  • allanallan Posts: 61,903Questions: 1Answers: 10,148 Site admin

    A side-effect of fnUpdate seems to be that it destroys existing event bindings on all cells of the updated row. Is this avoidable?

    Not if the event handlers are attached to the elements inside the cells, since the innerHTML is written to. You could use a delegated event on the tbody, which is what I typically do myself.

    For your code - a shorter version using the new API only would be:

    table.cells( null, 0 ).indexes().each( function ( idx ) {
      if ( table.cell( idx ).data() != new_cell_data ) {
        table.cell( idx ).data( new_cell_data );
      }
    } );
    

    Allan

  • sronsieksronsiek Posts: 52Questions: 11Answers: 0

    Excellent - the cheat-sheet is great (just wish I'd found it earlier), as is the code snippet & event delegation hint.

    Thank you gentlemen.

This discussion has been closed.