Sort Categories by rowGroup.count
Sort Categories by rowGroup.count
Hi
Is it in some way possible to sort the categories built by rowGroup by the number of .count for each catergory? What i want is to categorize a list of log entries and the categories with the highest numbers should be topmost.
Alternatively is it possible to set the row.count() number in the rowGroup into every detail row of the specific category? This would solve the problem also i think.
Maybe someone has a hint in this issue!
This question has an accepted answers - jump to answer
Answers
Hi @worgor ,
This thread should help, it's asking the same thing. There's an example low down on the thread that should get you going.
Cheers,
Colin
Colin you are a star, thx a lot, i'll have look at it right now!! Thx!
Hi Colin
I tried your approach but was not very successful, unfortunatly i've to leave the ajax injection in my sample code so it's pretty hard to make a fiddle ... maybe you can have a look at it and tell me what i'm doing wrong - the categories are showing correct but the sorting of the total count is not working.
Hi @worgor ,
That's a lot of code to look at. You can create a fiddle with static data, just use
data
with a small dataset, and that would help to diagnose the issue.Cheers,
Colin
hi colin
i tried it here
http://live.datatables.net/hujabuhi/3/edit
but it won't even group the rows ... in general it's the original post with a few modifications - i thought removing the sum() and just placing the count wouldn't be a problem.
Looking at the browser's console you are getting this error:
Is there a reason why you are using
example.rows().invalidate();
instartRender
? You are getting the same errors inside initComplete. Likely you don't want to use invalidfate() or draw() in these two places.Commented out those lines, here is the updated example:
http://live.datatables.net/hujabuhi/4/edit
I haven't followed the thread closely so not sure what exactly you are trying to show in the test case. But its running now so Colin can take a look or if you want to summarize what the test case should be doing that its not it would be helpful.
Kevin
oh thx kevin, i missed this line, and no there is no reason for the .invalidate() in startRender() - i was just minimizing the changes of the original sample from this link https://datatables.net/forums/discussion/comment/143344#Comment_143344 - i tried to adopt this sample colin mentioned i failed a couple of times so i just wanted to have a working sample ... i've no clou why it is behaving differnt to the oirignal sample ... Thx again Kevin
To summarize the testecase - what i want to achieve is that the row.count() is sortable in a seperate column even if it is created in the row.group() start event. so the goal is that all documents are counted under a specific group and can then be sorted so people can see where the most errors occured!
Hi @worgor ,
I think we should move away from that example and look at your specific data, since those links are confusing things.
Does this fit the bill? http://live.datatables.net/januciha/1/edit
I've added an extra column to store the count, which you can then order on.
Cheers,
Colin
Hi Colin
You are right for sure, there is a lot going on in these samples! The example in the link is somehow only loading but i will try the approach in the row.group(). Thank you very much! Kind regards Andy
I'm trying out this example but i'm confused - what exactly makes it possible to sort all categories by the "count" column? i removed the "orderfixed" even the "order" ... it had no effect and sometimes it worked, sometimes not ... i think it's just trial and error now because i've no clue what exactly does what ... is there a way to isolate this feature in the code? moreover i've to collapse the categories ... so a lot of complex stuff ... i think i could move to a two table version which would make it much easier ... this would be my favourite though!
IT WORKS - thank you Colin, thank you Kevin!!! This was there part which made it happen although i don't know what it does :-)
Here is the complete datatable for everybody who ever wants to collapse all groups and want to sort the row count:
`
let collapsedGroups = {};