Adding extra rows at runtime

Adding extra rows at runtime

RayHerringRayHerring Posts: 11Questions: 5Answers: 0

Is it possible to add extra rows to a table while it is being rendered, i've looked at the 'add rows' example but i'm not sure if it is exactly what i am looking for.

The data itself comes via ajax and works perfectly, i get a row in the table for every row in the dataset/temp-table, however i have a couple of sales stats that i need to show per row (quantity sold and sales).

Have included a screenshot of the table (as it is currently rendered, can't provide a webpage link as it is an internal point of sale).

http://puu.sh/avBC1/0ea7d04296.png

json data is here: https://onedrive.live.com/redir?resid=6934E091A89EF706!763&authkey=!ADtWtDm0FXm17QQ&ithint=file%2cjson

Basic attempt at using DT Live: http://live.datatables.net/cuvoreb/1/

Not sure how to get the json data into the live view.

Basically, under each row i want a subrow that has to always be showing with the sales quantity.

Answers

  • RayHerringRayHerring Posts: 11Questions: 5Answers: 0

    It isn't pretty, and there is probably a way better way of doing it, but i have managed to make it work by using:

    "rowCallback": function(row, data) {
            var sales = data.ttSalesReportData[0].Current_Sales;
            var table = $("#ttSalesReport").DataTable();
    
            var sales_totals = $('<tr class="bold font-size-large data-row"></tr>');
            sales_totals.append('<td></td><td></td><td class="text-right">Sales Totals</td>');
    
            for ( i = 0; i <= sales.length - 1; i++ ) {
              sales_totals.append('<td class="text-right">' + sales[i] + '</td>');
            }
    
            table.row(row).child(sales_totals).show();
          }
    
  • RayHerringRayHerring Posts: 11Questions: 5Answers: 0

    Moved it from rowCallback to fnCreatedRow to speed up the searching, etc... as i found things were going slow using the former, likely because that was being called every single time and not just when the table was being first rendered.

This discussion has been closed.