mirror of
https://github.com/DataTables/DataTables.git
synced 2024-12-02 14:24:11 +01:00
Fix example: When there is no data, can't use reduce
in footer callback
This commit is contained in:
parent
1d159700bd
commit
c5414152ed
@ -1 +1 @@
|
|||||||
d4712d3aca31b553dc940f1d99ed8cda039399e2
|
3caec7dedaf1192da42f7d023dd86b45e95c5938
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#example').dataTable( {
|
$('#example').dataTable( {
|
||||||
"footerCallback": function ( row, data, start, end, display ) {
|
"footerCallback": function ( row, data, start, end, display ) {
|
||||||
var api = this.api();
|
var api = this.api(), data;
|
||||||
|
|
||||||
// Remove the formatting to get integer data for summation
|
// Remove the formatting to get integer data for summation
|
||||||
var intVal = function ( i ) {
|
var intVal = function ( i ) {
|
||||||
return typeof i === 'string' ?
|
return typeof i === 'string' ?
|
||||||
@ -34,20 +35,20 @@ $(document).ready(function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Total over all pages
|
// Total over all pages
|
||||||
var total = api
|
data = api.column( 4 ).data();
|
||||||
.column( 4 )
|
total = data.length ?
|
||||||
.data()
|
data.reduce( function (a, b) {
|
||||||
.reduce( function (a, b) {
|
|
||||||
return intVal(a) + intVal(b);
|
return intVal(a) + intVal(b);
|
||||||
} );
|
} ) :
|
||||||
|
0;
|
||||||
|
|
||||||
// Total over this page
|
// Total over this page
|
||||||
var pageTotal = api
|
data = api.column( 4, { page: 'current'} ).data();
|
||||||
.column( 4, { page: 'current'} )
|
pageTotal = data.length ?
|
||||||
.data()
|
data.reduce( function (a, b) {
|
||||||
.reduce( function (a, b) {
|
|
||||||
return intVal(a) + intVal(b);
|
return intVal(a) + intVal(b);
|
||||||
} );
|
} ) :
|
||||||
|
0;
|
||||||
|
|
||||||
// Update footer
|
// Update footer
|
||||||
$( api.column( 4 ).footer() ).html(
|
$( api.column( 4 ).footer() ).html(
|
||||||
@ -518,7 +519,8 @@ $(document).ready(function() {
|
|||||||
example:</p><code class="multiline brush: js;">$(document).ready(function() {
|
example:</p><code class="multiline brush: js;">$(document).ready(function() {
|
||||||
$('#example').dataTable( {
|
$('#example').dataTable( {
|
||||||
"footerCallback": function ( row, data, start, end, display ) {
|
"footerCallback": function ( row, data, start, end, display ) {
|
||||||
var api = this.api();
|
var api = this.api(), data;
|
||||||
|
|
||||||
// Remove the formatting to get integer data for summation
|
// Remove the formatting to get integer data for summation
|
||||||
var intVal = function ( i ) {
|
var intVal = function ( i ) {
|
||||||
return typeof i === 'string' ?
|
return typeof i === 'string' ?
|
||||||
@ -528,20 +530,20 @@ $(document).ready(function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Total over all pages
|
// Total over all pages
|
||||||
var total = api
|
data = api.column( 4 ).data();
|
||||||
.column( 4 )
|
total = data.length ?
|
||||||
.data()
|
data.reduce( function (a, b) {
|
||||||
.reduce( function (a, b) {
|
|
||||||
return intVal(a) + intVal(b);
|
return intVal(a) + intVal(b);
|
||||||
} );
|
} ) :
|
||||||
|
0;
|
||||||
|
|
||||||
// Total over this page
|
// Total over this page
|
||||||
var pageTotal = api
|
data = api.column( 4, { page: 'current'} ).data();
|
||||||
.column( 4, { page: 'current'} )
|
pageTotal = data.length ?
|
||||||
.data()
|
data.reduce( function (a, b) {
|
||||||
.reduce( function (a, b) {
|
|
||||||
return intVal(a) + intVal(b);
|
return intVal(a) + intVal(b);
|
||||||
} );
|
} ) :
|
||||||
|
0;
|
||||||
|
|
||||||
// Update footer
|
// Update footer
|
||||||
$( api.column( 4 ).footer() ).html(
|
$( api.column( 4 ).footer() ).html(
|
||||||
|
Loading…
Reference in New Issue
Block a user