Topic: Datatable Custom Sort Order (mdbreact 4.10.0)

vasechkin free asked 5 years ago


Hi,

If I want to display dates in the datatable in the local format "HH:MM:SS DD/MM/YYYY". Is it possible to attach a custom sorting function so the order will be correct when sorted by date? Or alternatively, is it possible to provide a custom formatting function?

Thank you.


movework premium answered 5 years ago


Hello,

I have the same problem.

I also use DataTable with jQuery and I know that sometimes it's hard to get it right.

Do you think that there would be a way to arrive at our result by passing as value something like this (I tried but it does not work):

  • const data = { columns: ..., rows: {date: "< span class='d-none'>yyyy-mm-dd HH:MM< /span>dd-mm-yyyy hh:mm"}}
  • const data = { columns: ..., rows: {date: < div dangerouslySetInnerHTML={{__html: "< span class='d-none'>yyyy-mm-dd HH:MM< /span>dd-mm-yyyy hh:mm}}">< /div>}}

I was doing like that with jQuery but here I block.

Thank you in advance for your answer


Jakub Mandra staff commented 5 years ago

Hi,

It's not possible because table elements do not allow to attach any html as a child.

You can sort your data before you attach it to the table

In React version we are working on an update, where the user would be able to choose the type of sorting.

Best,

Jakub


Jakub Mandra staff answered 5 years ago


Hi,

It is not possible, unfortunately. Datatables use JS sort function and update the inner state of the component. It is not quite possible to allow passing custom functions, but you can bind already sorted data to the component.

Best,

Jakub



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 React
  • MDB Version: 4.8.4
  • Device: PC
  • Browser: Chrome
  • OS: Linux
  • Provided sample code: No
  • Provided link: No
Tags