sorting of datatable for date, datetime and time column

sorting of datatable for date, datetime and time column

bczm8703bczm8703 Posts: 2Questions: 1Answers: 0
edited July 28 in DataTables 1.10

the column in my table will be dynamically created on runtime.
the table might have either date or DateTime or time, all 3 types, either of the 2 types or one of them
Currently, my datatable sorting for these columns are treated as a string during the sort
the format of the data will be like the following
date: 17/07/2021
DateTime: 23/04/2021 15:45
time: 16:34

Answers

  • colincolin Posts: 12,481Questions: 0Answers: 2,117

    Yep, there would be no automatic search that could handle that - for example, how should it compare "17/07/2021" to "16:34"? Which one should be considered before the other?

    That said, you can create your own sort plugin, here are a few you could use as a template, in which you would define your own logic.

    Colin

  • bczm8703bczm8703 Posts: 2Questions: 1Answers: 0

    there will not be a chance for a single column to have a different type. it is just that before runtime i would not be able to know which column will be date, or which column will be datetime or time

  • allanallan Posts: 54,574Questions: 1Answers: 8,534 Site admin

    Use this plug-in to register the date / time formats you want to be able to sort. DataTables will then automatically be able to detect columns with those formats.

    Allan

Sign In or Register to comment.