language.info: how to change message when there's only one entry (feature request?)
language.info: how to change message when there's only one entry (feature request?)
I see language.info options for zero entries showing, zero records found, etc. I might be missing something, but what I do not see is the ability to directly vary the info when there is one and only one entry. Since variation between singular and plural is common to most languages, it might be a useful feature to add. A case in point: I changed a scrollable table to say "Showing END Entries". When there is only one entry, I'd like it to say "Showing 1 Entry" instead of "Showing 1 Entries". Is there a way to do this that I'm missing?
Replies
My question now is how do I make this say "Showing 1 entry" when I filter down to one record? I've read up on the 'search.dt' event, but I don't see how to inject a new string into the info value without making a new call to dataTable() every time the user changes the search criteria. That seems wrong.
Unfortunately there isn't a trivial way to do this in DataTables at the moment. You could using
infoCallback
, but there isn't a nice simple way to handle the singular case.Allan
That seems to be what I'm looking for. I'll experiment with it when I get around to it and post the code when I come up with something. Thanks Allan.
That would be great - thanks.
The language options are something I'd like to improve more, but its exceptionally difficult to offer the required options for the various languages. If there was just a single number being displayed I've got a function for that, but with multiple numbers being displayed its a bit of a nightmare.
There was a GNU page that describe the issues with internationalisation which I now can't find, but their general overview of getttext describes some of the issues nicely (should you be interested...).
Allan
As it turns out, using
infoCallback
was very straightforward.I got into this because the default info is better suited to a paged table than a scrolling one. In a scrolling table the
start
andend
parameters are redundant, as they will always equal 1 andtotal
, respectively. The info would say something like "Showing 1 to 40 of 40 entries" when it could just as well say "Showing 40 entries". So, I wanted this (I also wanted to say "record" instead of "entry"):x
records in the table, wherex>1
and we aren't applying a filter, say "Showingx
records".y
ofx
records", wherex
is the total records in the table, andy
is the total records shown.In the options list for the
DataTable()
call, I started with this (although I changed_END_
to_TOTAL_
after I got clearer on the meanings of the parameters):Which works ok, but misses requirement 3 above. As I write this, I see I could nest another ternary operator into the
info
parameter:But that's rather messy. Using
infoCallback
is clearer and more manageable. I got rid oflanguage
altogether and substituted this:Awesome - thanks for the feedback! I'll look into how to improve that options in future.
Allan