Refinement of display when all rows are showing
Refinement of display when all rows are showing
I made some minor changes to our copy of dataTables 1.7.0 which I thought I would post back for possible future inclusion. The display when the table is showing all available rows could be nicer; in particular, I wanted it to say "Showing all N entries" instead of "Showing 1 to N of N entries".
I added a new format string:
[code]
this.oLanguage = {
...
"sInfoAll": "Showing all _TOTAL_ entries",
[/code]
and reorganized the last two if blocks in _fnUpdateInfo into one with inner conditionals:
[code]
if ( oSettings.fnRecordsDisplay() === 0 &&
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{
/* Empty record set */
jqFirst.html( oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix );
}
else if ( oSettings.fnRecordsDisplay() === 0 )
{
/* Empty record set after filtering */
jqFirst.html( oSettings.oLanguage.sInfoEmpty +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
oSettings.oLanguage.sInfoPostFix );
}
else
{
/* Normal record set */
var info;
if ( oSettings._iDisplayStart === 0 &&
oSettings.fnDisplayEnd() === oSettings.fnRecordsDisplay() &&
oSettings.oLanguage.sInfoAll )
{
/* Showing all records */
info = oSettings.oLanguage.sInfoAll.replace('_START_', sStart)
.replace('_END_', sEnd)
.replace('_TOTAL_', sTotal);
}
else
{
/* Showing one page of a larger set */
info = oSettings.oLanguage.sInfo.replace('_START_', sStart)
.replace('_END_', sEnd)
.replace('_TOTAL_', sTotal);
}
if ( oSettings.fnRecordsDisplay() < oSettings.fnRecordsTotal() )
{
/* Record set after filtering */
info += ' ' + oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()));
}
info += oSettings.oLanguage.sInfoPostFix;
jqFirst.html( info );
}
[/code]
Note that I'm checking for the presence of the new sInfoAll string and replacing all three members so the previous behavior will occur by either specifying null or using the sInfo value for sInfoAll.
Thanks,
John
I added a new format string:
[code]
this.oLanguage = {
...
"sInfoAll": "Showing all _TOTAL_ entries",
[/code]
and reorganized the last two if blocks in _fnUpdateInfo into one with inner conditionals:
[code]
if ( oSettings.fnRecordsDisplay() === 0 &&
oSettings.fnRecordsDisplay() == oSettings.fnRecordsTotal() )
{
/* Empty record set */
jqFirst.html( oSettings.oLanguage.sInfoEmpty+ oSettings.oLanguage.sInfoPostFix );
}
else if ( oSettings.fnRecordsDisplay() === 0 )
{
/* Empty record set after filtering */
jqFirst.html( oSettings.oLanguage.sInfoEmpty +' '+
oSettings.oLanguage.sInfoFiltered.replace('_MAX_', sMax)+
oSettings.oLanguage.sInfoPostFix );
}
else
{
/* Normal record set */
var info;
if ( oSettings._iDisplayStart === 0 &&
oSettings.fnDisplayEnd() === oSettings.fnRecordsDisplay() &&
oSettings.oLanguage.sInfoAll )
{
/* Showing all records */
info = oSettings.oLanguage.sInfoAll.replace('_START_', sStart)
.replace('_END_', sEnd)
.replace('_TOTAL_', sTotal);
}
else
{
/* Showing one page of a larger set */
info = oSettings.oLanguage.sInfo.replace('_START_', sStart)
.replace('_END_', sEnd)
.replace('_TOTAL_', sTotal);
}
if ( oSettings.fnRecordsDisplay() < oSettings.fnRecordsTotal() )
{
/* Record set after filtering */
info += ' ' + oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()));
}
info += oSettings.oLanguage.sInfoPostFix;
jqFirst.html( info );
}
[/code]
Note that I'm checking for the presence of the new sInfoAll string and replacing all three members so the previous behavior will occur by either specifying null or using the sInfo value for sInfoAll.
Thanks,
John
This discussion has been closed.
Replies
Nice one - thanks.
Regards,
Allan
I did forget one case thought: exactly one row, in which case the best message would be "Showing one entry". I added one more sInfo flavor in my version (sInfoOne). For completeness, there should be an option for exactly two also (see http://en.wikipedia.org/wiki/Plural).
Here's the code I ended up with. I also adjusted some default messages (since sInfoFiltered made the div wrap, which I thought was ugly). I think there could be a further simplification by just making all the branches of the if set sInfoFmt and then optionally tacking sInfoFiltered on at the end.
[code]
"sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
"sInfoEmpty": "Showing no entries",
"sInfoOne": "Showing one entry",
"sInfoAll": "Showing all _TOTAL_ entries",
"sInfoFiltered": "(of _MAX_ total)",
[/code]
[code]
_fnMap( oSettings.oLanguage, oLanguage, 'sInfo' );
_fnMap( oSettings.oLanguage, oLanguage, 'sInfoEmpty' );
_fnMap( oSettings.oLanguage, oLanguage, 'sInfoOne' );
_fnMap( oSettings.oLanguage, oLanguage, 'sInfoAll' );
[/code]
[code]
else
{
/* Normal record set */
var sInfoFmt;
if ( oSettings._iDisplayStart === 0 &&
oSettings.fnDisplayEnd() === oSettings.fnRecordsDisplay() &&
oSettings.fnDisplayEnd() === 1 &&
oSettings.oLanguage.sInfoOne )
{
/* Showing only record */
sInfoFmt = oSettings.oLanguage.sInfoOne;
}
else if ( oSettings._iDisplayStart === 0 &&
oSettings.fnDisplayEnd() === oSettings.fnRecordsDisplay() &&
oSettings.oLanguage.sInfoAll )
{
/* Showing all records */
sInfoFmt = oSettings.oLanguage.sInfoAll;
}
else
{
/* Showing one page of a larger set */
sInfoFmt = oSettings.oLanguage.sInfo;
}
var sInfo = sInfoFmt.replace('_START_', sStart)
.replace('_END_', sEnd)
.replace('_TOTAL_', sTotal);
if ( oSettings.fnRecordsDisplay() < oSettings.fnRecordsTotal() )
{
/* Record set after filtering */
sInfo += ' ' + oSettings.oLanguage.sInfoFiltered.replace('_MAX_',
oSettings.fnFormatNumber(oSettings.fnRecordsTotal()));
}
sInfo += oSettings.oLanguage.sInfoPostFix;
jqFirst.html( sInfo );
}
[/code]
Regards,
Allan