Multiply values and apply style in Datatables

Multiply values and apply style in Datatables

ADuslonADuslon Posts: 2Questions: 1Answers: 0

Dear community,
I would like to understand how to multiply column values and apply style in Datatables.

Currently my columns section looks like this :

"columns": [
{ data: "id" },
{ data: "brand" },
{ data: "description" },
{ data: "nb_ref" },
{ sortable : false, data: "cost", render: $.fn.dataTable.render.number( ' ', '.', 2, '€' ) },
]

what I would like in the 5th column is to multiply the "cost" by the "nb_ref" (the value of the 4th column) and still apply the number format.

Any idea about how to achieve ?

thanks

Adam

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    You would need to have a function for columns.render - third parameter will be the data for the entire row. You would then need to format it as a number within that function.

    return $.fn.dataTable.render.number(',', '.', 0, '$').display(sum);
    

    This thread has an example of that.

    Colin

  • ADuslonADuslon Posts: 2Questions: 1Answers: 0

    This is great. Thank you Colin !

This discussion has been closed.