1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-18 11:52:11 +01:00

New: Language callback function for the information element. This can be used to customise the language shown in the information element beyond what is possible with the built in language string options (for example plurals). The arguments are fnInfoCallback( oSettings, iStart, iEnd, iMax /*no filter*/, iTotal /*after filter*/, sOut /*DT rendered string*/ ) - 2520

This commit is contained in:
Allan Jardine 2010-08-17 23:29:12 +01:00
parent 8e2efc004f
commit 9e6094e792
2 changed files with 138 additions and 21 deletions

View File

@ -967,7 +967,8 @@
"sPrevious": "Previous",
"sNext": "Next",
"sLast": "Last"
}
},
"fnInfoCallback": null
};
/*
@ -4651,56 +4652,56 @@
return;
}
var jqFirst = $(oSettings.aanFeatures.i[0]);
var
sMax = oSettings.fnFormatNumber(oSettings.fnRecordsTotal()),
sStart = oSettings.fnFormatNumber(oSettings._iDisplayStart+1),
sEnd = oSettings.fnFormatNumber(oSettings.fnDisplayEnd()),
sTotal = oSettings.fnFormatNumber(oSettings.fnRecordsDisplay());
iStart = oSettings._iDisplayStart+1, iEnd = oSettings.fnDisplayEnd(),
iMax = oSettings.fnRecordsTotal(), iTotal = oSettings.fnRecordsDisplay(),
sStart = oSettings.fnFormatNumber( iStart ), sEnd = oSettings.fnFormatNumber( iEnd ),
sMax = oSettings.fnFormatNumber( iMax ), sTotal = oSettings.fnFormatNumber( iTotal ),
sOut;
if ( oSettings.fnRecordsDisplay() === 0 &&
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{
/* Empty record set */
jqFirst.html( oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix );
sOut = oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix;
}
else if ( oSettings.fnRecordsDisplay() === 0 )
{
/* Rmpty record set after filtering */
jqFirst.html( oSettings.oLanguage.sInfoEmpty +' '+
sOut = oSettings.oLanguage.sInfoEmpty +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
oSettings.oLanguage.sInfoPostFix );
oSettings.oLanguage.sInfoPostFix;
}
else if ( oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{
/* Normal record set */
jqFirst.html( oSettings.oLanguage.sInfo.
sOut = oSettings.oLanguage.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal)+
oSettings.oLanguage.sInfoPostFix );
oSettings.oLanguage.sInfoPostFix;
}
else
{
/* Record set after filtering */
jqFirst.html( oSettings.oLanguage.sInfo.
sOut = oSettings.oLanguage.sInfo.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal) +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()))+
oSettings.oLanguage.sInfoPostFix );
oSettings.oLanguage.sInfoPostFix;
}
/* No point in recalculating for the other info elements, just copy the first one in */
var n = oSettings.aanFeatures.i;
if ( n.length > 1 )
if ( oSettings.oLanguage.fnInfoCallback != null )
{
var sInfo = jqFirst.html();
for ( var i=1, iLen=n.length ; i<iLen ; i++ )
{
$(n[i]).html( sInfo );
}
sOut = oSettings.oLanguage.fnInfoCallback( oSettings, iStart, iEnd, iMax, iTotal, sOut );
}
var n = oSettings.aanFeatures.i;
for ( var i=0, iLen=n.length ; i<iLen ; i++ )
{
$(n[i]).html( sOut );
}
}
@ -6204,6 +6205,7 @@
_fnMap( oSettings, oInit, "aoSearchCols", "aoPreSearchCols" );
_fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" );
_fnMap( oSettings, oInit, "bJQueryUI", "bJUI" );
_fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
if ( typeof oInit.fnDrawCallback == 'function' )
{

View File

@ -0,0 +1,115 @@
// DATA_TEMPLATE: dom_data
oTest.fnStart( "fnInfoCallback checks" );
$(document).ready( function () {
var mPass;
$('#example').dataTable();
/* Basic checks */
oTest.fnTest(
"null by default",
null,
function () { return $('#example').dataTable().fnSettings().oLanguage.fnInfoCallback == null; }
);
oTest.fnTest(
"Agrument length",
function () {
$('#example').dataTable( {
"bDestroy": true,
"fnInfoCallback": function( oS, iStart, iEnd, iMax, iTotal, sPre ) {
mPass = arguments.length;
return sPre;
}
} );
},
function () { return mPass == 6; }
);
oTest.fnTest(
"Settings first",
function () {
$('#example').dataTable( {
"bDestroy": true,
"fnInfoCallback": function( oS, iStart, iEnd, iMax, iTotal, sPre ) {
mPass = (oS == $('#example').dataTable().fnSettings()) ? true : false;
return sPre;
}
} );
},
function () { return mPass; }
);
oTest.fnTest(
"Start arg",
function () {
$('#example').dataTable( {
"bDestroy": true,
"fnInfoCallback": function( oS, iStart, iEnd, iMax, iTotal, sPre ) {
return iStart;
}
} );
},
function () { return $('#example_info').html() == "1"; }
);
oTest.fnTest(
"End arg",
function () {
$('#example').dataTable( {
"bDestroy": true,
"fnInfoCallback": function( oS, iStart, iEnd, iMax, iTotal, sPre ) {
return iEnd;
}
} );
},
function () { return $('#example_info').html() == "10"; }
);
oTest.fnTest(
"Max arg",
function () {
$('#example').dataTable( {
"bDestroy": true,
"fnInfoCallback": function( oS, iStart, iEnd, iMax, iTotal, sPre ) {
return iMax;
}
} );
},
function () { return $('#example_info').html() == "57"; }
);
oTest.fnTest(
"Max arg - filter",
function () {
$('#example').dataTable().fnFilter("1.0");
},
function () { return $('#example_info').html() == "57"; }
);
oTest.fnTest(
"Total arg",
function () {
$('#example').dataTable( {
"bDestroy": true,
"fnInfoCallback": function( oS, iStart, iEnd, iMax, iTotal, sPre ) {
return iTotal;
}
} );
},
function () { return $('#example_info').html() == "57"; }
);
oTest.fnTest(
"Total arg - filter",
function () {
$('#example').dataTable().fnFilter("1.0");
},
function () { return $('#example_info').html() == "3"; }
);
oTest.fnComplete();
} );