Request: oLanguage Functions!

Request: oLanguage Functions!

jsmith88jsmith88 Posts: 10Questions: 0Answers: 0
edited November 2013 in Feature requests
Allan,

In a lot of my code, I allow a property of an object to be string literal, OR a function that returns a string. This makes for very flexible code. I think it would be really cool if you expanded the oLanguage settings to include this functionality.

For example, internally, after filtering takes place and zero results are found, we can set the message that's displayed using "oLanguage.sZeroRecords". There have been many situations when I've wished this message could be dependent on the current state of my application.

What about something like this?

Request changes in datatables.net...
[code]
// ... filter applied, time to present the sZeroRecords message...

var messageToDisplay = ($.type(oLanguage.sZeroRecords) === "function")
? oLanguage.sZeroRecords() // invoke the function
: oLanguage.sZeroRecords; // string

// use messageToDisplay however it's being used now ...
[/code]

Which could reference something like this:

[code]
$("#table").dataTable({
oLanguage: {
sZeroRecords: function() {
if(myWebApp.someStateActive()) {
return "No matches found; why not try turning off this filter you have active."
}
else {
return "No matches found. Sorry, we don't have any suggestions or hints, either!"
}
}
}
});
[/code]

I suppose if this change were made, sZeroRecords would have to change names too. ;)

Just a suggestion, I find myself desiring this feature nearly every time I use datatables.

Thanks for the amazing library!

Replies

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin
    I think this is a very good idea. I've wondered before if it might be possible to have a number of the options as functions. I'm thinking I might be able to put it into my _fnMap function rather than needing to duplicate the code...

    > I suppose if this change were made, sZeroRecords would have to change names too. ;)

    DataTables 1.10 is going to favour camelCase. All options will have a camelCase alias, which will be the options that are documented. The hungarian notation style will still be supported for backwards compatibility, but for reasons such as this, camelCase is the way forward... :-)

    Allan
This discussion has been closed.