Custom footer containing the total items count

8 posts, 0 answers
  1. Jacob
    Jacob  avatar
    49 posts
    Member since:
    Apr 2016

    Posted 30 Nov 2016 Link to this post

    Hello Telerik,

    Our solution needs a footer row for the grids, for now containing only the item count.

    I have browsed some of solution for this such as this one, but it won't attend to my needs for a couple of reasons:

    - the footer cells need to be merged as if there was a column spam there

    - the footer needs to be independent of a column. A simple count of all the rows before and after the grid built-in filtering.

    Regarding the second point, please do correct me if I am wrong, but I am assuming that the

    <telerik:GridViewDataColumn.AggregateFunctions>
                            <telerik:CountFunction Caption="Count: "  />
    </telerik:GridViewDataColumn.AggregateFunctions>

     

    is out of question, since it is column-bound. And the reason why it won't serve is because my grid has a columnchooser. if the user unselect that column, the count will disappear. Which is pointless. So I didn't even bother looking too deep on how to merge cells horizontally, since I believe a row just below the grid containing the count should be the way to go.

    Furthermore my grid receives a VirtualQueryableCollectionView as datasource. And the only indicator of the Rows Count that it has is the VirtualItemCount = data.Count(). The problem is that property won't change in case the user filters the grid.

    Finally my question is: where can I find the Grid Total Rows Count that will also show the right number after filtering?

     

    Thank you

  2. Jacob
    Jacob  avatar
    49 posts
    Member since:
    Apr 2016

    Posted 30 Nov 2016 Link to this post

    Hi again, Telerik

    I have a few updates for this topic. First of all, I could answer my own question with this:

    <TextBlock Text="{Binding ElementName=CustomGridview, Path=Items.Count}" />

    it works like a charm, even after playing with the filter.

    But I would like to take the chance this topic is up to ask for some guidance on what other way there is to show the row counts of each group right next to it, when grouping the grid. As seen in the very first picture of this link.

    this code:

    <telerik:GridViewDataColumn.AggregateFunctions>
                            <telerik:CountFunction Caption="Count: "  />
    </telerik:GridViewDataColumn.AggregateFunctions>

    works. but I noticed that when I use it the performance drops significantly on the loading of the grid.

    So now my question is: where can I find the grid group rows count that will also show the right number after filtering?

     

    Thank you, Telerik

     

  3. Jacob
    Jacob  avatar
    49 posts
    Member since:
    Apr 2016

    Posted 30 Nov 2016 in reply to Jacob Link to this post

    ok, i am almost there. I could find the itemcount for each group, now i just need to concatenate them to their group's headers.

    This is where i get stuck. Group Header property, anyone?

    here is my code

    public static void GridviewOnGrouped(object sender, GridViewGroupedEventArgs gridViewGroupedEventArgs)
    {
        RadGridView gridView = ((RadGridView)sender); 
        foreach (QueryableCollectionViewGroup group in gridView.Items.Groups)
        {
            int itemCount = group.ItemCount;
        }
    }
  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1173 posts

    Posted 02 Dec 2016 Link to this post

    Hello Jacob,

    What you can do in this case, is to define a CountFunction for only one of your columns and since the GroupHeaderRow displays all aggregate results from the AggregateResults (no matter if the column is hidden or not) you will get a single result with your entries count.

    this.clubsGrid.Columns[0].AggregateFunctions.Add(new CountFunction());

    Would such an approach be suitable for your scenario?

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
  5. Jacob
    Jacob  avatar
    49 posts
    Member since:
    Apr 2016

    Posted 06 Dec 2016 in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

    I tried the suggested code, and it works fine on small grids, although I couldn't find a way to concatenate a "Number of rows" text to the count. But it won't really matter, since the performance drops significantly on larger ones (having over 10000 rows and 20 columns). Unfortunately it just takes forever to load.

    Is there an alternative to this?

    Thank you

  6. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1173 posts

    Posted 06 Dec 2016 Link to this post

    Hello Jacob,

    I'm attaching a sample project where the aforementioned approach seems to be working correctly without any significant effect on performance. Could you please have a look at it and let me know if it differs from the setup you have at your end in any way?

    Thank you in advance for your cooperation on the matter.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
  7. Jacob
    Jacob  avatar
    49 posts
    Member since:
    Apr 2016

    Posted 08 Dec 2016 in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

    Thank you for investing time on building that sample. It runs smooth, however, I noticed you are still using ObservableCollection, which doesn't apply to my scenario. I made a simple modification on your sample approaching my scenario and now it presents the delay I was talking about. Here is how the GetClubs() method looks like to return a VirtualQueryableCollectionView object:

    public static VirtualQueryableCollectionView GetClubs()
    {
        var db = new DataClasses1DataContext();
     
        var data = from user in db.Users
                   select new UsersDTO
                   {
                       Name = user.Name,
                   };
     
        return new VirtualQueryableCollectionView(data) { LoadSize = 300, VirtualItemCount = data.Count() };
    }
    public class UsersDTO
    {
        public string Name { get; set; }  // name
    }

    and the grid should have that column

    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"
                                    Header="Name}"
                                    Width="0.15*" />
    </telerik:RadGridView.Columns>

     

    finally in the viewmodel the type of clubs should change from ObservableCollection<Clubs> to VirtualQueryableCollectionView

     

    the data should come from a table containing 10000 rows. and as you might have noticed I use linq to sql for that.

    that is the way I could simulate my scenario based on your sample project. please let me know what can I do to avoid this issue.

    Thank you

  8. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1173 posts

    Posted 12 Dec 2016 Link to this post

    Hello Jacob,

    In order to perform the grouping of items, all entries should be loaded from the database. That is the reason why the grouping operation takes more time to complete.

    What I can suggest in such a scenario is to use the QueryableCollectionView class instead and page the bound data using RadDataPager. I'm attaching a sample project demonstrating the approach I have in mind. Please let me know if it would work for you.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Back to Top