I have a G1 table (Gramex) in UI which has columns with date and time but as string. When the user sorts the respective column with the help of inbuilt sort option, it sorts the data as string not as date.
How to apply date/time sorting on a column which has date/time as string in G1 table in gramex
191 views Asked by mishraP At
1
Approach 1
The easiest way would be if the date and time were formatted like
YYYY-MM-DD HH:MM:SS. For example, '2022-09-04 03:02:01'. This is a string that can be sorted consistently with the datetime.You can create such strings in Python with the
datetime.isoformat()function.Approach 2
If your dates are stored in a different format, e.g.
04-09-2022, etc., then IF the data is loaded from a file, not a database, then you can modify the data with thefunction:transform to convert the column to the right data format.For example:
This converts the
date_col(replace this with your date column name) from any date format Pandas recognizes into aYYYY-MM-DD HH:MM:SStype format that is sortable.If the data is loaded from a database, then you DO need to convert it into a sortable format first.