Show entries based on Groups not Rows
Show entries based on Groups not Rows
marshall_99
Posts: 1Questions: 1Answers: 0
Hello, I have a question... I have row grouped datatable (even with collapsible function). On first page is 20 entries and 3 groups and on second page is 10 entires and 8 groups... I have this issue, that I want to show for example 2 groups on one page (and it wouldnt matter how many entries are there). Because it looks weird if I have only 3 closed groups on one page and 8 closed groups on second page.
I hope you understand.
Thank you call
Answers
You can use the
rowGroup().dataSrc()
API to change the data source, ie, change the number of groups shown. You can use it in thedraw
event so that each table draw you check to see how many groups you want and use -api rowGroup().dataSrc()to apply the grouping. You may also need to use
-api order()` to make sure the table is properly ordered.Not sure how you want to determine the grouping but you could use
rows().every()
with aselector-modifier
of{page: 'current'}
to iterate the rows on the page.If you want help with this then start by building a running example and specify how to determine the number of groups to show.
Kevin
I am trying to show entries based on Groups using the RowGroup extension for my groups. This is the only post I came across that was similar to what I'm looking for and there doesn't seem to be a clear conclusion on how to do this. Seeing an example would be very helpful. This is also an older post so I'm wondering if anything has changed. Let me know If I should make a new post for this.
Below is the current table I have. It has nested groupings with a total, and count aggregate. Since I am setting up the grouping using rowGroup extension, I'm not sure how I would use the rowGroup().datasrc() in the draw api and then determine grouping by rows.every(). Any help would be appreciated. I'm still somewhat new to using datatables.
pastebin https://pastebin.com/RCfgAnbV
or code below:
@CucumberOwl Your
rowGroup.dataSrc
is['0.display', 1, 2]
. I'm not sure what0.display
is. Probably should just be[0, 1, 2]
. The docs state this about the usage:The
order
option will need to set the order of the groups your are using. Something like this:order: [[0, 'desc'], [1, 'desc'], [2, 'desc']],
. See this example of multilevel grouping.I think the OP was looking for a way to control how many groups are displayed per page. Are you asking for the same?
If you still need help please provide a link to your page or a test case replicating the issue so we can see what you have to offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Yes, I am looking for a way to show 10 groups (first group level) per page instead of 10 entries. I need to keep the groups together on one page. It is confusing if a group gets split between pages.
Thanks for the link to the test case. See my test case here: live.datatables.net/wimumubu/1/edit
To answer other questions:
I am using ['0.display', 1, 2] as the grouping specifically '0.display' because I am using the data-sort option on the first group for the Invoice period. I need to display the date in a certain format but need to be able to order by the actual date. using data-sort makes that field an object, so I need to specify grouping by the display of the date or it does not group properly.
I'm not sure about the sorting. By default, I care about the sort by date. I suppose I could add order to the other groups.
Thanks in advance.
If you don't sort the columns you are grouping then the groups could be split. See this example where I changed one
Type 1
toType 2
.http://live.datatables.net/wimumubu/3/edit
Your data is in the proper order to work without sorting. RowGroup relies on the ordering to be correct to properly display the groups.
Thats neat, didn't know that would work.
I think this would require some creative coding Per your example each group may have different number of rows. The
page.len()
will need to be set to display 10 groups with all the rows. Any search, sort or paging could change this so it would need checked for eachdraw
except thedraw()
executed withpage.len()
. Probably possible to do but seems pretty complicated.Kevin