This is a migrated thread and some comments may be shown as answers.

Custom footer containing the total items count

7 Answers 894 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 30 Nov 2016, 02:08 PM

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

7 Answers, 1 is accepted

Sort by
0
Jacob
Top achievements
Rank 1
answered on 30 Nov 2016, 02:52 PM

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

 

0
Jacob
Top achievements
Rank 1
answered on 30 Nov 2016, 04:00 PM

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;
    }
}
0
Dilyan Traykov
Telerik team
answered on 02 Dec 2016, 03:42 PM
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.
0
Jacob
Top achievements
Rank 1
answered on 06 Dec 2016, 10:41 AM

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

0
Dilyan Traykov
Telerik team
answered on 06 Dec 2016, 01:44 PM
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.
0
Jacob
Top achievements
Rank 1
answered on 08 Dec 2016, 10:44 AM

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

0
Dilyan Traykov
Telerik team
answered on 12 Dec 2016, 12:13 PM
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.
Tags
GridView
Asked by
Jacob
Top achievements
Rank 1
Answers by
Jacob
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or