RowGroup with paging

RowGroup with paging

hadarhadar Posts: 17Questions: 4Answers: 0

Hi,

I add the option of RowGroup in my application and I want to add the count of elements in each group.
I add the following line :
startRender: function ( rows, group ) {
return group +' ('+rows.count()+' rows)';
}

The problem is that I have paging and if the number of elements so if for example I have 50 rows in group and I show only 25
the number that I will see is 25 and not 50 so looks like the rows parameter is only refer to the rows shown in the HTML.

Is there a way to show the total number of rows even if the number is greater then number of rows in page ?

Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765
    Answer ✓

    Take a look at this example from this thread.

    Kevin

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin

    I've been mulling this over - initially I was a little surprised that it is only the rows from the current page (and I wrote this! A while back, but still...). First thing is that the docs need to be clearer - I've committed a change which will be deployed to the site soon.

    Secondly - Kevin's example shows a good workaround for the moment. Basically query the table for the data in the current group.

    That said, this only works for first level grouping. The simple solution is to calculating the grouping for all groups, which I could do - the code is all there. But the reason (I've recalled) for limiting it to the current page only was for performance. Why calculate groupings for potentially tens of thousands (or more) records, when only displaying ten!

    I need to think about this a bit more. I most certainly see the issue here and would like to resolve it.

    Allan

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    How about a new parameter that contains all the rows, something like this:

    endRender( rows, group, level, allRows )
    

    Kevin

  • hadarhadar Posts: 17Questions: 4Answers: 0

    Thanks,
    I used the example and it work.

    If the user select group he can chnage disable the paging (I give him the option to choose 25\50\100\All maybe need to automataclly change to all)

    This raise 2 question ;
    1. Can I sort the table by the count of rows in each group ?
    2. Is there support for collapse/expand ?

    Another question : what does pluck(5) mean ?

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin

    1) No. Nice idea, but sorting is done on the data in the rows - the grouping doesn't count as a "row" even although it does display like one. If you were to put the count into each row, then that would work.

    2) Also no - sorry. Expand and collapse is something that does get asked about row group. It could possibly be done through filtering, but I suspect not trivial to add.

    3) `-api pluck(5) means that it will get the 6th (remember, 0 indexing) item from the array. Imagine for example the following data for a table - two rows, and two columns:

    [
      [ 1, 2 ],
      [ 3, 4 ]
    ]
    

    Using rows().data() to get the data for the rows and then rows().data().pluck(1) would give you [2, 4].

    @kthorngren - That's exactly what I was thinking. I was wondering if there is a way to see if the callback was specified with four parameters - if so, do the extra calculation needed for it. I suspect there will be, but not certain yet (might need a wrapper function).

    Allan

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    Is there support for collapse/expand ?

    Someone, maybe Colin, came up with a solution a few years ago. There are lots of thread with different questions about the solution so take a look around the forum. See if this thread gets you started.

    Kevin

  • hadarhadar Posts: 17Questions: 4Answers: 0

    Hi,

    I add the option for collapse and it works. Thanks

    Problem I see is that suppose I have the following data :

    field1,field2,field3
    name1,val1,1
    name2,val1,1
    name3,val1,2
    name4,val1,2
    name5,val2,1
    name6,val2,1

    If I group by field2 it works OK
    If I group by field3 than the group appear more than once

    Group by Origin field :

  • hadarhadar Posts: 17Questions: 4Answers: 0

    Looks like it need to be sorted to make it works,
    If first,second and forth lines are in same group but third line is not than it will group the first,second , and forth line will be in another group

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    Yes, for rowGroup to work you need to sort by the column(s) being grouped.

    Kevin

Sign In or Register to comment.