Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It should be possible to set localization methods through data attributes #7058

Open
joshuajeschek opened this issue Nov 13, 2023 · 2 comments
Labels
core Issues stemming from our compiled or source JavaScript files. feature Issues asking for a new feature to be added, or an existing one to be extended or modified. locale Issues regarding errors in locale extensions.

Comments

@joshuajeschek
Copy link

Description

Since it is possible to set most functions throught data attributes, such as data-query-params for the table or data-formatter for columns, it should also be possible to set the methods for localization via data attributes.
The following should be possible:

<table
// other options ...
data-format-no-matches="formatNoMatches"
// ...
/>
function formatNoMatches() {
  return 'No matching records found.';
}

However, this results in the following error:

Uncaught TypeError: this.options.formatNoMatches is not a function
bootstrap-table.min.js:10:104521

The only way to set it currently is like this:

$('table').bootstrapTable('refreshOptions', { formatNoMatches });

However, I am not using javascript to instantiate my table and i would like to keep it that way, keeping the configuration in the html data tags.

@wenzhixin wenzhixin added the feature Issues asking for a new feature to be added, or an existing one to be extended or modified. label Nov 14, 2023
@wenzhixin
Copy link
Owner

Another option is that you can override the default format option.

Object.assign($.fn.bootstrapTable.locales['en-US'], {
  formatNoMatches () {
    return 'No matching records found.'
  }
})
Object.assign($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['en-US'])

I'm not sure how many users need to set the format with data-attribute, mark it as a feature first, and then consider implementing it into code if there are a large number of users who need it.

@joshuajeschek
Copy link
Author

Thanks. It is a good option, but it doesn't quite apply to my usecase:

  • using the standard translations provided
  • overriding only formatNoMatches
  • since my application already uses a different tool for translation though, I am not reimplementing formatNoMatches for every language, but only once, accessing the tool in the override function.

@wenzhixin wenzhixin added core Issues stemming from our compiled or source JavaScript files. locale Issues regarding errors in locale extensions. labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues stemming from our compiled or source JavaScript files. feature Issues asking for a new feature to be added, or an existing one to be extended or modified. locale Issues regarding errors in locale extensions.
Projects
None yet
Development

No branches or pull requests

2 participants