BeldenSpartan free asked 2 years ago


Is it possible to sort on formatted numerical values within a datatable?

Consider the examples provided in the documentation: https://mdbootstrap.com/docs/standard/data/datatables/

If we sort on Salary in any of the provided examples, it treats the salary as a string, so the sorted values are incorrect. Is it possible to sort formatted values (currency, etc.) as numbers instead of strings?


BeldenSpartan free answered 2 years ago


Haven't heard back...wanted to make sure my question wasn't missed. How can I pass it as a number yet format it as a currency in the table?

Sorting as a string in the provided example (https://mdbootstrap.com/docs/standard/data/datatables/#docsTabsOverview) doesn't make any sense.

In the following example I found for the jquery version (https://mdbootstrap.com/docs/b4/jquery/tables/datatables1/), it looks like sort can work on values formatted for currency. How do I do this in the standard version of MDB?


Dawid Wajszczuk staff commented 2 years ago

It can't be done currently. You can only add a number without the currency. But proper task has been added.


BeldenSpartan free commented 2 years ago

With all due respect, this is a very big miss. I cannot use MDB if I have to choose between displaying unformatted numbers that can be sorted, or displaying formatted numbers that cannot be sorted. Either option is unacceptable.


Dawid Wajszczuk staff commented 2 years ago

Thanks for your feedback.


Dawid Wajszczuk staff answered 2 years ago


Hi,

You need to pass it as a Number via JS instead of String and it will be sorted as Number.

Keep coding,
Dawid


BeldenSpartan free commented 2 years ago

How can I pass it as a number yet format it as a currency in the table?



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.10.2
  • Device: PC
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: Yes