table.rows() does not bring up the row that was added programmatically using Editor's create() api

table.rows() does not bring up the row that was added programmatically using Editor's create() api Posts: 6Questions: 4Answers: 0


I wanted to provide a test case for my question, but I couldn't get Editor plugin to work on

Here is an overview of what I am trying to do:

  1. Initialize Datatables A with AJAX JSON data. I am also doing a summation of some column values in its footer callback.
  2. Initialize Datatables B with AJAX JSON data. Also has a footer callback which shows sums of values in Table B on one row, and net sum of values from Table A and Table B on second row.
  3. Adding a row to Table A using Editor API create().submit(). I am submitting JSON object to server side to adding record in database and return object creates a row in Datatable A. Upon creation of the row in Datatable A, its footer callback executes again, and updates the totals in footer. All well.
  4. As per business rules, I need to delete the record in Datatable B(if what was just added to Datatable A already existed in Datatable B ). I use the datatableB.row(<ID of row>).remove().draw() API to remove record from Datatable B. Upon removal, Datatable B's footer callback runs and updates totals. Fine.
  5. However, the second row of footer which is supposed to show the grand total of Datatable A footer and Datatable B footer is being miscalculated. Here is the footer callback in Datatable B:

"footerCallback": function ( row, data, start, end, display ) {

            var sumUCYMins = 0;

            $.each(data, function(index, value){
                if(value._cyHours != null)
                    sumUCYMins = sumUCYMins + value._cyHours;


            var api = this.api();

            var sumAssgCYMins = 0;

            var aData = datatableA.rows().data();
            $.each(aData, function(index, value){
                if(value._cyHours != null)
                    sumAssgCYMins = sumAssgCYMins + value._cyHours;


            var totalCYMins = sumAssgCYMins + sumUnassgCYMins;

                    // Update footer
            $( api.column( 4 ).footer() ).html( 

            $('tr:eq(1) th:eq(4)', api.table().footer()).html(convertMinutesToHoursAndMinutes(totalCYMins));   


When printing aData in console, I always get the rows that were present in Datatables at the time of initialization. I don't see the row that was added using Datatables A Editor's create() API.

What would be the correct way to get the most recent rows of Datatables A?

This question has an accepted answers - jump to answer


Sign In or Register to comment.