RowGroup - How to group by a new (dynamic/computed) column?
RowGroup - How to group by a new (dynamic/computed) column?
Hi,
I'm trying to create a new column, named Dateonly like "2022-12-28", coming from a Timestamp (1672255040037.893) and use it to group my data coming from a database table (local).
Actually the Dateonly field is defined in the database table, and grouping works fine (obviously).
What I want is to remove Dateonly from the DB table and create it on-the-fly, and use it to group my data when the user clicks on "Group by Date" link.
The sample I prepared for you works and shows the essence only of the thing: http://live.datatables.net/cujagihi/3/edit
I'm unsuccessfully working on this task from 3 days searching/trying everything.
Could someone help me?
Many thanks.
Replies
One option is to use
rowGroup.startRender
to convert the timestamp like you did incolumns.render
. For example:http://live.datatables.net/cujagihi/5/edit
Kevin
Hmmmmm... it seems it's not working. I get "No Group" clicking on "Group by Date" and it's veeeeryyy slooooow
OK, I was testing too early. I can see you'r still working on it
Nope I'm not still working on it. Not sure what you mean by slow. Can you elaborate?
I should have mentioned that you will need to use
rowGroup().dataSrc()
inrowGroup.startRender
to determine which group is being shown and return the data accordingly.Kevin
Ok thanks I will give a look
Finally I did it: http://live.datatables.net/cujagihi/10/edit
It's a bit tricky and could be done better, but at least it works.
I didn't use any new column and everything comes from Timestamp. And this is the first problem to solve now, because, for the same date, there are many Timestamp values which are wrongly considered distinct groups.
Now clicking the Group by... links works fine.
Any suggestion to make it better?
Anyway... thank you Kevin
I see. Sounds like you will want to use
rowGroup.dataSrc
as a function instead ofrowGroup.startRender
. See the comment in the docs. For example:http://live.datatables.net/cujagihi/11/edit
Note that I hard coded the Timestamp column number in the
rowgroup-datasrc
event becauseval
is a function which causes an exception error with this line:I'll let you determine the logic needed, based on your solution, to dynamically determine the column number.
Kevin