count grouping item
count grouping item
m75sa
Posts: 132Questions: 30Answers: 0
Considering this example:
https://jsfiddle.net/lbriquet/ua4yLscx/
i need to count grouped items and this works but what i want is also to count items grouped by two columns.
To be clear:
In this case i see that it counts items grouped by OFFICE, is it possible also to group by OFFICE and POSITION?
Thanks for your help
This question has an accepted answers - jump to answer
Answers
Do you mean you want two levels of grouping? If so, then yes, that is possible in RowGroup and is shown in this example.
If I've misunderstood and you are looking for something like more control over the grouping text, can you clarify what you are looking for please?
Thanks,
Allan
@allan i replicated the table i have.
So what i want is count the grouped items by letter and by status so:
result like this:
AA FULL 3
AA EMPTY 1
BB EMPTY 1
CC EMPTY 1
DD EMPTY 1
live.datatables.net/vosuwixo/1/edit?html,js,output
The
rows
parameter ofrowGroup.startRender
contains the rows displayed on the page. You can userows().every()
to loop through these rows. Something like this:Kevin
@kthorngren thanks. Can you help me by updating the script posted on the live.datatable ? (live.datatables.net/vosuwixo/1/edit?html,js,output)
Sorry, for me it's easier to understand by example. Thanks in advance for the support!
I fixed your test case so it runs:
http://live.datatables.net/zawijijo/1/edit
I'm not sure what you want to count so I just count the number of
FULL
cells. I used$(data[1]).text()
to get the text out of thediv
in the cell.Kevin
mm... AA FULL will be 4 and you count 3
AA EMPTY is just 1
BB full is 1 and you don't count...
maybe something doesn't work...
I'm confused. In the example you provided AA has three rows with
FULL
. The other groups don't have any rows withFULL
. The example is just counting the number of timesFULL
is found. You are welcome to change the code to count the items the way you want.Kevin
have a look on this, i cleaned the table:
live.datatables.net/tofebufe/1/edit?html,js,output
considering this table i would like to have a result like this:
AA EMPTY. 2
AA FULL. 1
BB EMPTY 3
CC EMPTY 2
CC FULL 1
possible?
Are you saying you want
AA EMPTY
as a group andAA FULL
as a different group? If yes then you can userowGroup.dataSrc
as a function to combine the two columns to build the groups.Otherwise update my code to count the rows with
EMPTY
and display both counts.If you want further help please make sure the test case runs properly.
Kevin
hi @kthorngren, yes, you're right. The first case is what i need:
AA EMPTY as a group and AA FULL as a different group.
but also BB EMPTY as group and BB FULL as a group...etc...
Can you help me to adapt the test case? Sorry and thanks
I fixed your test case so it runs properly. You had two
tbody
tags which won't work - Datatables didin't find any rows. Going forward please make sure your test cases run properly so we don't have to fix syntax and other errors that are not part of the question.http://live.datatables.net/tofebufe/3/edit
I added
order
to sort the columns appropriately androwGroup.dataSrc
as a function to combine the two columns.Kevin
ah fantastic!
thanks. last thing: if i don't want to display all the items below each group? so if i want only grouped items with the total ?
anyway you are the number one, my friend!
Add the collapsed code back into the solution.
Kevin
hi @kthorngren , thanks a lot. work perfectly