koalyptus / TableFilter

A Javascript library making HTML tables filterable and a bit more :)
https://www.tablefilter.com
MIT License
324 stars 95 forks source link

ColOps: Format of the calculated number doesn't respect locale #789

Closed rimace closed 3 years ago

rimace commented 3 years ago

Describe the bug The ColOps extension ignores the options of the TableFilter options. All operations result in a US American format, even if the locale was to de for example. I also set the thousands_separator and decimal_separator, those those seemed to be ignored by ColOps

Reproduction steps: Steps to reproduce the behavior:

  1. Create a table using and additionally use these options:
    locale: 'de',
    thousands_separator: '.',
    decimal_separator: ',',
  2. Use ColOps to calculate some sums/means

Expected behavior The number format of the sums should match the locale's format that was defined in the options.

Observed behavior: The number format of the sums are always US American format, using comma as thousand separator and point as a decimal separator.

Screenshots If applicable, add screenshots to help explain your problem. Screenshots and GIFs which follow reproduction steps to demonstrate the problem

TableFilter version: 0.7.3 Browser and version: Firefox 78 ESR and 80 OS and version: Fedora 32 Device: HP EliteBook G2

Additional information/context: Currently this is the workaround I use:

[...]
on_after_operation: function() {
    column.innerHTML = Number.parseFloat(column.innerHTML.replace(",", "")).toLocaleString("de-DE");
}
koalyptus commented 3 years ago

Hi @rimace, Please have a look to this demo: http://www.tablefilter.com/data-types.html for formatting numbers.

Cheers

rimace commented 3 years ago

Hello @koalyptus , thanks for your help, this works! While surfing the code, I found that the thousandsSeperator in tablefilter.js:818 is never used anywhere in the code.

Still I close this issue as I now have the answer thanks to you :)

koalyptus commented 3 years ago

Tx for spotting that confusing left-over reference to thousandsSeperator, I will remove it in next version(s). Cheers