Anyone with tabulator and Luxon experience?

Hi !

I use tabulator and luxon.js in a ui-template node, to get some of the incoming datas, including timestamp, to be displayed in a table.
The code in UI*template is using luxon to convert the incoming timestamp to a human-readable DateTime , so far so good.

Problem is when I want to use a sorter on top of the columns, I can't get it to sort the table properly based on the DateTime column.... I tried the DateTime sorter available on Tabulator website but no luck. So for now I use a second column which directly uses the timestamp without any formatting, and with that one I can sort without any problem....

Thanks in advance,

Jerome

Hello,

Would it be possible to share a small Demo flow to show what you have tried ?
An Inject node with some sample data and the ui-template node with your code so we can test it.

Hi, thanks for your willing to help.

I m far from the system for a few days, but will provide some sample code as soon as I can.

Jerome

Hi, in the meantime I ve been able to make it work.

Happy to share if anyone is interested.

It would be best to share, as this is what the forum is about. Share now as in six months you may not respond due to any number of issues. If you mark a solution, there should actually be a solution for people to see.

Sure there it is.

In the template node hosting the tabulator formatting, here is the column part, with incoming Epoch timestamp in ms . It also includes a custom sorter to sort the column based on timestamp value instead of the human-readable date/time :

                title: "Time",
                field: "booking.scheduleInfo.startTimestamp",
                headerFilter: "input",
                formatter: function (cell, formatterParams) {
                    // Convert incoming milliseconds to Luxon DateTime and format
                    var milliseconds = cell.getValue();
                    var dateTime = luxon.DateTime.fromMillis(milliseconds);

                    // Format the datetime as desired (e.g., 'yyyy-MM-dd HH:mm:ss')
                    return dateTime.toFormat('dd-MM-yyyy HH:mm');
                }
                ,
                width: 100,
                sorter: function (a, b, aRow, bRow, column, dir, sorterParams) {
                    var dateA = a; // Assuming the timestamp is in milliseconds
                    var dateB = b; // Assuming the timestamp is in milliseconds
                    return dateA - dateB;

                }
            },

Note it makes use of luxon library as I started my tests with it, but I guess I could be able to do without it....

Result :

image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.