Jquery and Bootstrap table to find the sum of collumn with paging
$(document).ready(function () {
var Table = $('#example').DataTable({
"bSort": false,
"footerCallback": function (row, data, start, end, display, val) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
total = api
.column(0, { 'search': 'applied' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
var CD = total;
// Total over this page
pageTotal = api
.column(0, { page: 'current' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
$(api.column(0).footer()).html(
pageTotal.toFixed(2)
);
// Update footer
$("#totFW").html(
total.toFixed(2)
);
// Total over all pages
total = api
.column(1, { 'search': 'applied' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
var CDT = pageTotal;
// Total over this page
pageTotal = api
.column(1, { page: 'current' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
$(api.column(1).footer()).html(
pageTotal.toFixed(2)
);
// Update footer
$("#totFD").html(
total.toFixed(2)
);
$("#totCredit").html(
(total + CD).toFixed(2)
);
var p = document.getElementById("totCredit").innerHTML;
if (p < 0) {
document.getElementById("totCredit").className = "red";
}
else if (p > 0) {
document.getElementById("totCredit").className = "green";
}
$("#totDebit").html(
(pageTotal + CDT).toFixed(2)
);
var x = document.getElementById("totDebit").innerHTML;
if (x < 0) { document.getElementById("totDebit").className = "red"; }
else if (x > 0) { document.getElementById("totDebit").className = "green"; }
}
});
});
See Other Tutorial :
* AngularJS CRUD Operation : Select Insert Edit Update and Delete using AngularJS in ASP.Net MVC
* AngularJS With ASP.NET MVC
* Convert Rows to columns using 'Pivot' in SQL Server
* Mvc Registration page With user exist using Ajax method
* MVC 4 How to Perform Insert Update Delete Edit Select Operation
* MVC4 Edit,update,Delete,cancel inside gridview using sql database
* MVC 4 Gridview To Display Data Using SQL Server Database With Simple code
* Login page in asp.net Mvc4 Web application
* Mvc4 How to bind Dropdown List using Sql Database
* Gridview find control in asp.net
Sign up here with your email
ConversionConversion EmoticonEmoticon