开发者

What's a recommendable way to search/sort I18n'ed strings with DataTables when using AJAX as a data source?

So, my team and I are working on this application, where we use the DataTables jQuery plugin (http://datatables.net/) to present tabular data provided by our Rails (3.0.7) backend.

We're having a problem with the interaction between the datatable's builtin AJAX search and sorting functionalities and Rails' I18n support. Some of the columns present configuration data that comes from the database (created in the seed file) but is internationalized, since it's a fixed da开发者_开发问答ta set. When the user tries to search or sort, we should perform those operations over the visible, I18n'ed strings. But since search and sorting are delegated to the backend, the controller will perform the required queries over the internal versions of the strings and not the user-visible ones, which will lead to erroneous results.

The solution we thought of first was using the controller to:

  • perform the DB queries without any criteria and store the results;
  • I18n the required values in the result set;
  • then sort/filter the results.

But this would be too demanding on the server. Another option we considered was including the required I18ns in the tables that have I18n-able values, but this breaks the application's separation of concerns. So we're at a loss as to what mechanism we should employ to implement this feature. Can anyone help us out?


We had a similar problem: We had to maintain a db table with artwork names. Occasionally, artworks have different names in other languages. In order for those (we ended up calling them) synonyms to be searcheable, we inserted them into a synonyms table. This might not be a solution for your case.

Have a look at the ferret gem which provides indexing out of ruby code. You could simply rebuild this index in regular intervals and include the translations. That way, your controller can easily search them and it would not break the separation of concerns, as it is just another representation of your data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜