How to calculate sum of values from a row on client side

How to calculate sum of values from a row on client side

cha59cha59 Posts: 87Questions: 23Answers: 0

I have used footerCallback to sum my columns. Works fine and fast. I would like a similar clint side solution for the sum of a row. Untill now I have summed rows on the server side. It's working but slow. Would like to sum my rows on client side, but cannot figure out how. I have found a function that will sum the values of my rows, but all the rest of the data in my tabel comes from mySQL.

->field(
Field::inst( 'budget.fag' ),
Field::inst( 'budget.bem' ),
Field::inst( 'budget.sum' ),// In this field I would like the result of my function from budget.html
Field::inst( 'budget.u31' )->setFormatter( Format::ifEmpty( null ) ),
Field::inst( 'budget.u32' )->setFormatter( Format::ifEmpty( null ) ),
Field::inst( 'budget.u33' )->setFormatter( Format::ifEmpty( null ) ),
Field::inst( 'budget.u34' )->setFormatter( Format::ifEmpty( null ) ),

Is there a way to jump over a field without getting MySQL data in it leaving space on the html page to fill in the result of my function?
Or even better: What would be the DataTables optimal way of calculating the sum of values in a row?

Claus

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918
    Answer ✓
  • cha59cha59 Posts: 87Questions: 23Answers: 0

    Thanks a lot, Kevin. Got it working after a few hours and a nights sleep:
    ...
    { data: "budget.fag" },
    { data: null,
    render: function ( data, type, row ) {//summer uger på tværs
    return (intVal(row.budget.u31)+intVal(row.budget.u32))+intVal(row.budget.u32)+intVal(row.budget.u32)+intVal(row.budget.u33)+intVal(row.budget.u34)+intVal(row.budget.u35)+intVal(row.budget.u36)+intVal(row.budget.u37)+intVal(row.budget.u38)+intVal(row.budget.u39)+intVal(row.budget.u40)+intVal(row.budget.u41)+intVal(row.budget.u42)+intVal(row.budget.u43)+intVal(row.budget.u44)+intVal(row.budget.u45)+intVal(row.budget.u46)+intVal(row.budget.u347)+intVal(row.budget.u48)+intVal(row.budget.u49)+intVal(row.budget.u50)+intVal(row.budget.u51);
    },
    },
    { data: "budget.u31" },
    ...
    Claus

This discussion has been closed.