table.rows().every in submitSuccess event

table.rows().every in submitSuccess event

cent89cent89 Posts: 19Questions: 6Answers: 0

Hi, I have a problem with the submitSuccess event.
I have a function that reads all table rows and sum some columns. This function is called in the initComplete datatable function, and works well.
If i call the same function in the submitSuccess event, the table.rows().every function detects all rows execpt the row edited.
Where is the problem? Some code:

function update_totale_vendita(){
  var table = $('#righe_vendita').DataTable();  
  table.rows().every(function(rowIdx, tableLoop, rowLoop){
    var riga = this.data();
    //some calcs...
  });
}

//called in $(document).ready
editor.on('submitComplete', function ( e, data, action ) {    
    update_totale_vendita();
});

Thanks!
Roberto

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @cent89 ,

    I'm not seeing that here - it's showing the expected number of records. Would you be able to modify that example please do demonstrate the problem?

    Cheers,

    Colin

  • cent89cent89 Posts: 19Questions: 6Answers: 0

    Hi,
    I have done some tests.

    http://live.datatables.net/towatiba/1/edit?html,js,console,output

    I have declared editor and table before the document.ready function; in my code, I've "serverSide: true" DataTable attribute and "ajax:url" Editor attribute.
    In the live code it works, but on my pc no, it counts the number of rows minus 1.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    rows() will only give the rows available on the client-side if you are using server-side processing. So if you happen to have a page length of x and number of records in the table as x+1, then yes, that code would give you the expected number -1.

    Perhaps that is the difference between the example and your own?

    Allan

  • cent89cent89 Posts: 19Questions: 6Answers: 0

    Yes.
    But if I have 2 rows in the table and I update a cell, then the rows count is 1.
    I'm expecting a count error on insert with server-side, not on update...

    The server-side is necessary for my script. How I can resolve the problem?

    Roberto

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Just been debugging this with Colin and it does indeed appear that there is a bug in Editor related to this. Editor will remove any rows that it doesn't do an update for, and when using server-side processing it doesn't bother doing an updates since it will just be reloaded in the redraw. The removal of rows needed a conditional statement as well.

    The removal of rows was momentary which is why we've never caught this before - the end user sees nothing, but it can impact the API if you are using it in just the way you are. So thanks for letting us know about this! I've patched Editor and it will be available in 1.8.2 later this month.

    Until then, I would actually say that using submitComplete combined with server-side processing isn't actually appropriate since your event handler will execute before the new data has been loaded from the server-side.

    Instead listen for DataTables draw event and perform your calculations there.

    Allan

This discussion has been closed.