Adding two server side values into new column value
Adding two server side values into new column value
matt tonks
Posts: 3Questions: 2Answers: 0
I currently have a datatable and would like there to be a column which totals the values of the school_paid column and the other_paid into a separate column called total.
Could I have some guidance or an example on how to do this?
Here is my current code
var schoolTable = $('#schoolTable').DataTable({
dom: '<"pull-left top"l>B<"pull-right top"f> t<"bottom"ip><"clear">',
processing: true,
serverSide: true,
ajax:'http://localhost/manageit/get/schools',
columns: [
{data: 'item'},
{data: 'description'},
{data: 'supplier'},
{data: 'quantity'},
{data: 'start'},
{data: 'end'},
{data: 'school_paid'},
{data: 'other_paid'},
{data: 'total'}, // Needs to be a computed value of school_paid + other_paid
{data: 'isComplete'},
{
data: null,
className: "center",
defaultContent: '<button class="btn-link"><i class="material-icons">edit</i></button>'
}
],
buttons: [{
extend: 'pdfHtml5',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5]
},
className: "btn btn-md mx-5 btn-info"
}]
});
This discussion has been closed.
Answers
Use
columns.render
for this. You would use therow
function parameter to access the elements in the row and return something like this:return row.school_paid + row.other_paid
.Kevin