How can I sum a datatable column with JSON values?
How can I sum a datatable column with JSON values?
Josuemx10
Posts: 3Questions: 1Answers: 0
I have the following code and I want to sum the hours column but I can't do it
const promise1 = Promise.resolve(httpRequest.post("Post", "task/taskByProjectId", project, true));
promise1.then((value) => {
var table = $('#table-taskByProjectId').DataTable({
language: {
"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json"
},
paging: true,
"bDestroy": true,
lengthMenu: [
[5, 15, 30, -1],
[5, 15, 30, "Ver Todo"]
],
"columnDefs": [{
"className": "dt-center",
"targets": "_all"
}],
data: value,
columns: [
{
data: "nameTask",
"render": function (data, type, row, meta) {
return data;
}
},
{
data: "nombreUsuario",
"render": function (data, type, row, meta) {
return data;
}
},
{
data: "horas",
"render": function (data, type, row, meta) {
return data;
}
},
]
});
})
}
Can you help me please?
Answers
Are you trying to do something like this example?
You don't need to use
columns.render
to just return thedata
. Unles you are changing the data display you can remove it. All you need is this:The result will be the same.
Kevin
Hi Kevin, I appreciate your input, I will make the change.
Can you tell me how can I sum the total of the hours column in my example? Please
Did you look at the example I linked to? Are you trying to sum the column in the footer?
Kevin
Yes Kevin, i want to sum the column in the footer but i cant because i am using data values.
Here is that same example using
data
to load the data andcolumns.data
to define the data.http://live.datatables.net/qolenohu/1/edit
No changes to the code in the example. If this doesn't help then please post a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin