Topic: Datatables sorting formated columns

Espen Rønning priority asked 2 months ago


If you run the snippet and then sort the table by number you'll see that all columns are sorted correctly except column "Date 1" which remains unchanged after sorting.

Expected behavior All columns are sorted

Actual behavior The column Date 1 with the "format" attribute is not sorted

Resources (screenshots, code snippets etc.) https://mdbootstrap.com/snippets/standard/ererling-sande-no/6218977#js-tab-view


Kamila Pieńkowska staff answered 2 months ago


Format option is suppose to be used to change styles not the content of the cells. The way you use it you 'hardcode' specific value for every row.


Espen Rønning priority commented 2 months ago

That may be so, but this has been working flawlessly up until version 7.x.x I've been using this method a lot to format dates and numbers.

How would you propose to format a date in a userfriendly way (in my case dd.mm.yyyy) and still be able to sort the table on that date (with sorting by yyyy-mm-dd)?


Kamila Pieńkowska staff commented 2 months ago

You may try to listen to event render and run formatting then. That way you won't interfere with order of the cells. You can use data-mdb-field="DATE1" as querySelector to target cells from DATE1 column.



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: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 7.3.2
  • Device: PC
  • Browser: Chrome
  • OS: Windows 11
  • Provided sample code: No
  • Provided link: Yes