mirror of
https://github.com/DataTables/DataTables.git
synced 2025-01-19 12: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:
parent
8e2efc004f
commit
9e6094e792
42
media/js/jquery.dataTables.js
vendored
42
media/js/jquery.dataTables.js
vendored
@ -967,7 +967,8 @@
|
|||||||
"sPrevious": "Previous",
|
"sPrevious": "Previous",
|
||||||
"sNext": "Next",
|
"sNext": "Next",
|
||||||
"sLast": "Last"
|
"sLast": "Last"
|
||||||
}
|
},
|
||||||
|
"fnInfoCallback": null
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4651,56 +4652,56 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var jqFirst = $(oSettings.aanFeatures.i[0]);
|
|
||||||
var
|
var
|
||||||
sMax = oSettings.fnFormatNumber(oSettings.fnRecordsTotal()),
|
iStart = oSettings._iDisplayStart+1, iEnd = oSettings.fnDisplayEnd(),
|
||||||
sStart = oSettings.fnFormatNumber(oSettings._iDisplayStart+1),
|
iMax = oSettings.fnRecordsTotal(), iTotal = oSettings.fnRecordsDisplay(),
|
||||||
sEnd = oSettings.fnFormatNumber(oSettings.fnDisplayEnd()),
|
sStart = oSettings.fnFormatNumber( iStart ), sEnd = oSettings.fnFormatNumber( iEnd ),
|
||||||
sTotal = oSettings.fnFormatNumber(oSettings.fnRecordsDisplay());
|
sMax = oSettings.fnFormatNumber( iMax ), sTotal = oSettings.fnFormatNumber( iTotal ),
|
||||||
|
sOut;
|
||||||
|
|
||||||
if ( oSettings.fnRecordsDisplay() === 0 &&
|
if ( oSettings.fnRecordsDisplay() === 0 &&
|
||||||
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
|
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
|
||||||
{
|
{
|
||||||
/* Empty record set */
|
/* Empty record set */
|
||||||
jqFirst.html( oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix );
|
sOut = oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix;
|
||||||
}
|
}
|
||||||
else if ( oSettings.fnRecordsDisplay() === 0 )
|
else if ( oSettings.fnRecordsDisplay() === 0 )
|
||||||
{
|
{
|
||||||
/* Rmpty record set after filtering */
|
/* Rmpty record set after filtering */
|
||||||
jqFirst.html( oSettings.oLanguage.sInfoEmpty +' '+
|
sOut = oSettings.oLanguage.sInfoEmpty +' '+
|
||||||
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
|
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
|
||||||
oSettings.oLanguage.sInfoPostFix );
|
oSettings.oLanguage.sInfoPostFix;
|
||||||
}
|
}
|
||||||
else if ( oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
|
else if ( oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
|
||||||
{
|
{
|
||||||
/* Normal record set */
|
/* Normal record set */
|
||||||
jqFirst.html( oSettings.oLanguage.sInfo.
|
sOut = oSettings.oLanguage.sInfo.
|
||||||
replace('_START_', sStart).
|
replace('_START_', sStart).
|
||||||
replace('_END_', sEnd).
|
replace('_END_', sEnd).
|
||||||
replace('_TOTAL_', sTotal)+
|
replace('_TOTAL_', sTotal)+
|
||||||
oSettings.oLanguage.sInfoPostFix );
|
oSettings.oLanguage.sInfoPostFix;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Record set after filtering */
|
/* Record set after filtering */
|
||||||
jqFirst.html( oSettings.oLanguage.sInfo.
|
sOut = oSettings.oLanguage.sInfo.
|
||||||
replace('_START_', sStart).
|
replace('_START_', sStart).
|
||||||
replace('_END_', sEnd).
|
replace('_END_', sEnd).
|
||||||
replace('_TOTAL_', sTotal) +' '+
|
replace('_TOTAL_', sTotal) +' '+
|
||||||
oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
|
oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
|
||||||
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()))+
|
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 */
|
if ( oSettings.oLanguage.fnInfoCallback != null )
|
||||||
var n = oSettings.aanFeatures.i;
|
|
||||||
if ( n.length > 1 )
|
|
||||||
{
|
{
|
||||||
var sInfo = jqFirst.html();
|
sOut = oSettings.oLanguage.fnInfoCallback( oSettings, iStart, iEnd, iMax, iTotal, sOut );
|
||||||
for ( var i=1, iLen=n.length ; i<iLen ; i++ )
|
|
||||||
{
|
|
||||||
$(n[i]).html( sInfo );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "aoSearchCols", "aoPreSearchCols" );
|
||||||
_fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" );
|
_fnMap( oSettings, oInit, "iDisplayLength", "_iDisplayLength" );
|
||||||
_fnMap( oSettings, oInit, "bJQueryUI", "bJUI" );
|
_fnMap( oSettings, oInit, "bJQueryUI", "bJUI" );
|
||||||
|
_fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
|
||||||
|
|
||||||
if ( typeof oInit.fnDrawCallback == 'function' )
|
if ( typeof oInit.fnDrawCallback == 'function' )
|
||||||
{
|
{
|
||||||
|
115
media/unit_testing/tests_onhold/1_dom/fnInfoCallback.js
Executable file
115
media/unit_testing/tests_onhold/1_dom/fnInfoCallback.js
Executable 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();
|
||||||
|
} );
|
Loading…
x
Reference in New Issue
Block a user