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

New: The _START_, _END_, _MAX_ and _TOTAL_ macros for the information language strings can now be used in any info string, rather than being limited to just the ones noted in the documentation - a new internal function called _fnInfoMacros is introduced to allow this to work - 9211

This commit is contained in:
Allan Jardine 2012-04-13 11:29:56 +01:00
parent 2a60a96177
commit 8a66adc2d4
5 changed files with 110 additions and 86 deletions

View File

@ -21,7 +21,7 @@
*/ */
/*jslint evil: true, undef: true, browser: true */ /*jslint evil: true, undef: true, browser: true */
/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex*/ /*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros*/
(/** @lends <global> */function($, window, document, undefined) { (/** @lends <global> */function($, window, document, undefined) {
/** /**
@ -1371,22 +1371,22 @@
anRows[ 0 ].className = oSettings.asStripeClasses[0]; anRows[ 0 ].className = oSettings.asStripeClasses[0];
} }
var sZero = oSettings.oLanguage.sZeroRecords.replace( var oLang = oSettings.oLanguage;
'_MAX_', oSettings.fnFormatNumber(oSettings.fnRecordsTotal()) ); var sZero = oLang.sZeroRecords;
if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide ) if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
{ {
sZero = oSettings.oLanguage.sLoadingRecords; sZero = oLang.sLoadingRecords;
} }
else if ( oSettings.oLanguage.sEmptyTable && oSettings.fnRecordsTotal() === 0 ) else if ( oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
{ {
sZero = oSettings.oLanguage.sEmptyTable; sZero = oLang.sEmptyTable;
} }
var nTd = document.createElement( 'td' ); var nTd = document.createElement( 'td' );
nTd.setAttribute( 'valign', "top" ); nTd.setAttribute( 'valign', "top" );
nTd.colSpan = _fnVisbleColumns( oSettings ); nTd.colSpan = _fnVisbleColumns( oSettings );
nTd.className = oSettings.oClasses.sRowEmpty; nTd.className = oSettings.oClasses.sRowEmpty;
nTd.innerHTML = sZero; nTd.innerHTML = _fnInfoMacros( oSettings, sZero );
anRows[ iRowCount ].appendChild( nTd ); anRows[ iRowCount ].appendChild( nTd );
} }
@ -2380,57 +2380,41 @@
} }
var var
iStart = oSettings._iDisplayStart+1, iEnd = oSettings.fnDisplayEnd(), oLang = oSettings.oLanguage,
iMax = oSettings.fnRecordsTotal(), iTotal = oSettings.fnRecordsDisplay(), iStart = oSettings._iDisplayStart+1,
sStart = oSettings.fnFormatNumber( iStart ), sEnd = oSettings.fnFormatNumber( iEnd ), iEnd = oSettings.fnDisplayEnd(),
sMax = oSettings.fnFormatNumber( iMax ), sTotal = oSettings.fnFormatNumber( iTotal ), iMax = oSettings.fnRecordsTotal(),
iTotal = oSettings.fnRecordsDisplay(),
sOut; sOut;
/* When infinite scrolling, we are always starting at 1. _iDisplayStart is used only if ( iTotal === 0 && iTotal == iMax )
* internally
*/
if ( oSettings.oScroll.bInfinite )
{
sStart = oSettings.fnFormatNumber( 1 );
}
if ( oSettings.fnRecordsDisplay() === 0 &&
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{ {
/* Empty record set */ /* Empty record set */
sOut = oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix; sOut = oLang.sInfoEmpty;
} }
else if ( oSettings.fnRecordsDisplay() === 0 ) else if ( iTotal === 0 )
{ {
/* Rmpty record set after filtering */ /* Empty record set after filtering */
sOut = oSettings.oLanguage.sInfoEmpty +' '+ sOut = oLang.sInfoEmpty +' '+ oLang.sInfoFiltered;
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
oSettings.oLanguage.sInfoPostFix;
} }
else if ( oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() ) else if ( iTotal == iMax )
{ {
/* Normal record set */ /* Normal record set */
sOut = oSettings.oLanguage.sInfo. sOut = oLang.sInfo;
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal)+
oSettings.oLanguage.sInfoPostFix;
} }
else else
{ {
/* Record set after filtering */ /* Record set after filtering */
sOut = oSettings.oLanguage.sInfo. sOut = oLang.sInfo +' '+ oLang.sInfoFiltered;
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal) +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()))+
oSettings.oLanguage.sInfoPostFix;
} }
if ( oSettings.oLanguage.fnInfoCallback !== null ) // Convert the macros
sOut += oLang.sInfoPostFix;
sOut = _fnInfoMacros( oSettings, sOut );
if ( oLang.fnInfoCallback !== null )
{ {
sOut = oSettings.oLanguage.fnInfoCallback.call( oSettings.oInstance, sOut = oLang.fnInfoCallback.call( oSettings.oInstance,
oSettings, iStart, iEnd, iMax, iTotal, sOut ); oSettings, iStart, iEnd, iMax, iTotal, sOut );
} }
@ -2442,6 +2426,33 @@
} }
function _fnInfoMacros ( oSettings, str )
{
var
iStart = oSettings._iDisplayStart+1,
sStart = oSettings.fnFormatNumber( iStart ),
iEnd = oSettings.fnDisplayEnd(),
sEnd = oSettings.fnFormatNumber( iEnd ),
iTotal = oSettings.fnRecordsDisplay(),
sTotal = oSettings.fnFormatNumber( iTotal ),
iMax = oSettings.fnRecordsTotal(),
sMax = oSettings.fnFormatNumber( iMax );
// When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
// internally
if ( oSettings.oScroll.bInfinite )
{
sStart = oSettings.fnFormatNumber( 1 );
}
return str.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal).
replace('_MAX_', sMax);
}
/** /**
* Draw the table for the first time, adding all required features * Draw the table for the first time, adding all required features
@ -6129,7 +6140,8 @@
"_fnCallbackFire": _fnCallbackFire, "_fnCallbackFire": _fnCallbackFire,
"_fnJsonString": _fnJsonString, "_fnJsonString": _fnJsonString,
"_fnRender": _fnRender, "_fnRender": _fnRender,
"_fnNodeToColumnIndex": _fnNodeToColumnIndex "_fnNodeToColumnIndex": _fnNodeToColumnIndex,
"_fnInfoMacros": _fnInfoMacros
}; };
$.extend( DataTable.ext.oApi, this.oApi ); $.extend( DataTable.ext.oApi, this.oApi );

View File

@ -21,7 +21,7 @@
*/ */
/*jslint evil: true, undef: true, browser: true */ /*jslint evil: true, undef: true, browser: true */
/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex*/ /*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageCompat,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnApplyColumnDefs,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnJsonString,_fnRender,_fnNodeToColumnIndex,_fnInfoMacros*/
(/** @lends <global> */function($, window, document, undefined) { (/** @lends <global> */function($, window, document, undefined) {
/** /**

View File

@ -112,7 +112,8 @@ this.oApi = {
"_fnCallbackFire": _fnCallbackFire, "_fnCallbackFire": _fnCallbackFire,
"_fnJsonString": _fnJsonString, "_fnJsonString": _fnJsonString,
"_fnRender": _fnRender, "_fnRender": _fnRender,
"_fnNodeToColumnIndex": _fnNodeToColumnIndex "_fnNodeToColumnIndex": _fnNodeToColumnIndex,
"_fnInfoMacros": _fnInfoMacros
}; };
$.extend( DataTable.ext.oApi, this.oApi ); $.extend( DataTable.ext.oApi, this.oApi );

View File

@ -411,22 +411,22 @@ function _fnDraw( oSettings )
anRows[ 0 ].className = oSettings.asStripeClasses[0]; anRows[ 0 ].className = oSettings.asStripeClasses[0];
} }
var sZero = oSettings.oLanguage.sZeroRecords.replace( var oLang = oSettings.oLanguage;
'_MAX_', oSettings.fnFormatNumber(oSettings.fnRecordsTotal()) ); var sZero = oLang.sZeroRecords;
if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide ) if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
{ {
sZero = oSettings.oLanguage.sLoadingRecords; sZero = oLang.sLoadingRecords;
} }
else if ( oSettings.oLanguage.sEmptyTable && oSettings.fnRecordsTotal() === 0 ) else if ( oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
{ {
sZero = oSettings.oLanguage.sEmptyTable; sZero = oLang.sEmptyTable;
} }
var nTd = document.createElement( 'td' ); var nTd = document.createElement( 'td' );
nTd.setAttribute( 'valign', "top" ); nTd.setAttribute( 'valign', "top" );
nTd.colSpan = _fnVisbleColumns( oSettings ); nTd.colSpan = _fnVisbleColumns( oSettings );
nTd.className = oSettings.oClasses.sRowEmpty; nTd.className = oSettings.oClasses.sRowEmpty;
nTd.innerHTML = sZero; nTd.innerHTML = _fnInfoMacros( oSettings, sZero );
anRows[ iRowCount ].appendChild( nTd ); anRows[ iRowCount ].appendChild( nTd );
} }

View File

@ -43,57 +43,41 @@ function _fnUpdateInfo ( oSettings )
} }
var var
iStart = oSettings._iDisplayStart+1, iEnd = oSettings.fnDisplayEnd(), oLang = oSettings.oLanguage,
iMax = oSettings.fnRecordsTotal(), iTotal = oSettings.fnRecordsDisplay(), iStart = oSettings._iDisplayStart+1,
sStart = oSettings.fnFormatNumber( iStart ), sEnd = oSettings.fnFormatNumber( iEnd ), iEnd = oSettings.fnDisplayEnd(),
sMax = oSettings.fnFormatNumber( iMax ), sTotal = oSettings.fnFormatNumber( iTotal ), iMax = oSettings.fnRecordsTotal(),
iTotal = oSettings.fnRecordsDisplay(),
sOut; sOut;
/* When infinite scrolling, we are always starting at 1. _iDisplayStart is used only if ( iTotal === 0 && iTotal == iMax )
* internally
*/
if ( oSettings.oScroll.bInfinite )
{
sStart = oSettings.fnFormatNumber( 1 );
}
if ( oSettings.fnRecordsDisplay() === 0 &&
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{ {
/* Empty record set */ /* Empty record set */
sOut = oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix; sOut = oLang.sInfoEmpty;
} }
else if ( oSettings.fnRecordsDisplay() === 0 ) else if ( iTotal === 0 )
{ {
/* Rmpty record set after filtering */ /* Empty record set after filtering */
sOut = oSettings.oLanguage.sInfoEmpty +' '+ sOut = oLang.sInfoEmpty +' '+ oLang.sInfoFiltered;
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
oSettings.oLanguage.sInfoPostFix;
} }
else if ( oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() ) else if ( iTotal == iMax )
{ {
/* Normal record set */ /* Normal record set */
sOut = oSettings.oLanguage.sInfo. sOut = oLang.sInfo;
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal)+
oSettings.oLanguage.sInfoPostFix;
} }
else else
{ {
/* Record set after filtering */ /* Record set after filtering */
sOut = oSettings.oLanguage.sInfo. sOut = oLang.sInfo +' '+ oLang.sInfoFiltered;
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal) +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()))+
oSettings.oLanguage.sInfoPostFix;
} }
if ( oSettings.oLanguage.fnInfoCallback !== null ) // Convert the macros
sOut += oLang.sInfoPostFix;
sOut = _fnInfoMacros( oSettings, sOut );
if ( oLang.fnInfoCallback !== null )
{ {
sOut = oSettings.oLanguage.fnInfoCallback.call( oSettings.oInstance, sOut = oLang.fnInfoCallback.call( oSettings.oInstance,
oSettings, iStart, iEnd, iMax, iTotal, sOut ); oSettings, iStart, iEnd, iMax, iTotal, sOut );
} }
@ -104,3 +88,30 @@ function _fnUpdateInfo ( oSettings )
} }
} }
function _fnInfoMacros ( oSettings, str )
{
var
iStart = oSettings._iDisplayStart+1,
sStart = oSettings.fnFormatNumber( iStart ),
iEnd = oSettings.fnDisplayEnd(),
sEnd = oSettings.fnFormatNumber( iEnd ),
iTotal = oSettings.fnRecordsDisplay(),
sTotal = oSettings.fnFormatNumber( iTotal ),
iMax = oSettings.fnRecordsTotal(),
sMax = oSettings.fnFormatNumber( iMax );
// When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
// internally
if ( oSettings.oScroll.bInfinite )
{
sStart = oSettings.fnFormatNumber( 1 );
}
return str.
replace('_START_', sStart).
replace('_END_', sEnd).
replace('_TOTAL_', sTotal).
replace('_MAX_', sMax);
}