How to apply calculation on textbox values using jquery datatables?
How to apply calculation on textbox values using jquery datatables?
ahsannajam
Posts: 2Questions: 2Answers: 0
This program is working fine but I want to take all values of current-sales and closing-balance in input textbox so it can automatically calculate the result, I hope you understand.
Example: If i apply like this on all current-sales and closing-balance values so what should i change in code? Thanks
"current-sales": "<input type='text' value=40>",
"closing-balance": "<input type='text' value='37'>"
$(document).ready(function() {
$.each(dataSet, function(i, it) {
console.log(it);
it.cbTotal = it.nsp * it['closing-balance'];
it.csTotal = it.nsp * it['current-sales'];
});
// Table definition
var dtapi = $('#example').DataTable({
data: dataSet,
"deferRender": false,
"footerCallback": function(tfoot, data, start, end, display) {
var api = this.api();
var q = api.column(2).data().reduce(function(a, b) {
return a + b;
}, 0);
$(api.column(2).footer()).html(q);
$("#cstotal").val(q);
var p = api.column(3).data().reduce(function(a, b) {
return a + b;
}, 0);
$(api.column(3).footer()).html(p);
$("#cbtotal").val(p);
},
"order": [1],
"columns": [
// rest of the columns
{
data: "product_name"
}, {
data: "nsp"
}, {
data: "current-sales"
}, {
data: "closing-balance"
}
]
});
});
var dataSet = [{
"product_name": "Satou",
"nsp": 230,
"current-sales": 50,
"closing-balance": 23
}, {
"product_name": "panadol",
"nsp": 191,
"current-sales": 152,
"closing-balance": 131
}, {
"product_name": "disprine",
"nsp": 191,
"current-sales": 40,
"closing-balance": 37
}, {
"product_name": "panadol",
"nsp": 120,
"current-sales": 8,
"closing-balance": 173
}];
This discussion has been closed.