I am using Telerik controls Q1 2011 for silverlight. In one of my page I used RadGridView and requirement is to sort the data by three columns; Category, percentage and name (all ascending). So, the rows would be first sort by category and then percentage and then names. I found examples in demos and forum but they either talk about sort order or multiple column sorting in UI. What I need is to implement the stated sorting on page load, so I want that to be programmaticly written. Also, there is option of loading page again by button click, to I want to make sure the code can handle the data binding and formatting accordingly.
Please help.
-Jono
9 Answers, 1 is accepted
In order to sort multi columns programmatic, you will need to add multiple column sort descriptors to the collection, like:
ColumnSortDescriptor csd_1 = new ColumnSortDescriptor() { Column = this.clubsGrid.Columns["Name"], SortDirection = ListSortDirection.Descending }; this.clubsGrid.SortDescriptors.Add(csd_1); ColumnSortDescriptor csd_2 = new ColumnSortDescriptor() { Column = this.clubsGrid.Columns["Established"], SortDirection = ListSortDirection.Ascending }; this.clubsGrid.SortDescriptors.Add(csd_2);This way the grid will be first sorted by the Name column, then by the Established column. You may check RadGridView SortDescriptors collection for more info.
Best wishes,
Didie
the Telerik team
Now I am able to see what I wanted but there is one problem in exporting the grid in Excel.
When I export the rows, I get the footer row with some grid details populated. Attached is the sample. I just need the count at the end but not the control details. I tried setting 'ShowGroupFooters' and 'ShowColumnFooters' to false but of no help.
Please suggest.
As I can understand from your post you have grouped on some of the columns. Then you export and you get the details of the grouped rows. I have tried to reproduce this result, but when I set 'ShowGroupFooters=false' the details are not exported, just the footer.
May you please clarify what your scenario is? May you as well place some code how are you doing the export itself?
Regards,
Didie
the Telerik team
below is my xaml code
<
telerik:RadGridView Name="grid1" ColumnWidth="Auto" AutoGenerateColumns="False" AutoExpandGroups="True"
CanUserDeleteRows="False" CanUserInsertRows="False" IsReadOnly="True">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn UniqueName="Approaching" Header="Approaching.." DataMemberBinding="{Binding ApproachingTo}">
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:CountFunction Caption="Total :" ResultFormatString="{}{0}"/>
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
Here is C# code
private
void ArrangeGridRows()
{
if (grid1.GroupDescriptors.Count == 0)
{
var descriptor = new ColumnGroupDescriptor {Column = grid1.Columns["Approaching"]};
grid1.GroupDescriptors.Add(descriptor);
}
grid1.ShowGroupFooters =
false;
if (grid1.SortDescriptors.Count > 0) return;
var csdPercentHeld = new ColumnSortDescriptor
{
Column = grid1.Columns[
"Column1"],
SortDirection =
ListSortDirection.Ascending
};
grid1.SortDescriptors.Add(csdPercentHeld);
var csdSecurityName = new ColumnSortDescriptor
{
Column = grid1.Columns[
"Column2"],
SortDirection =
ListSortDirection.Ascending
};
grid1.SortDescriptors.Add(csdSecurityName);
}
When I export this in Excel I get bottom row as attached in screenshot. FYI, I have not extended any export logic.
Thanks
Have you checked our demo for exporting? You need to handle ElementExporting and provide values for group footers.
Regards,Vlad
the Telerik team
I put the below code to remove extra information.
private
void GridQueryResultsSummaryElementExporting(object sender, GridViewElementExportingEventArgs e)
{
if (e.Element == ExportElement.GroupFooterCell){e.Value = string.Empty;}}
Now my question is why I have to explicitly remove the un-neccessary content from export? Can't I just set some property of something, and direct gridview not to export group information beforehand?
Even after above workaround, I am getting a blank row between last data row and aggregate row.
Please suggest.
Regards
If you do not want group footer in the output you can simply set ShowGroupFooters to false for the export options.
Please refer to the demo I've posted!
Vlad
the Telerik team
Regards
It seems that you've missed to check the demo I've posted?
You need to set ShowGroupFooters for the export options - not for the grid.
Vlad
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
