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

[Solved] Sort order on multiple column programmaticly

9 Answers 311 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonathan
Top achievements
Rank 1
Jonathan asked on 28 Jun 2011, 03:15 AM
Hi,

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

Sort by
0
Dimitrina
Telerik team
answered on 28 Jun 2011, 12:38 PM
Hi Jonathan,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonathan
Top achievements
Rank 1
answered on 29 Jun 2011, 05:52 AM
Thanks for your reply.
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.
0
Dimitrina
Telerik team
answered on 04 Jul 2011, 02:27 PM
Hello Jonathan,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonathan
Top achievements
Rank 1
answered on 05 Jul 2011, 04:54 AM
Hi, thanks for helping.

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

0
Vlad
Telerik team
answered on 05 Jul 2011, 06:34 AM
Hello,

 Have you checked our demo for exporting? You need to handle ElementExporting and provide values for group footers.

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonathan
Top achievements
Rank 1
answered on 05 Jul 2011, 09:51 AM
Thanks for replying.

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

 

0
Vlad
Telerik team
answered on 05 Jul 2011, 09:54 AM
Hello,

 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!

Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jonathan
Top achievements
Rank 1
answered on 06 Jul 2011, 02:20 AM
Thanks Vlad but if you see my previous posts I have set the ShowGroupFooters to false at very beginning. Also, your fellow, Didie, had suggested the same thing but when it did not work I posted the code snippets. Please go through the whole communication to understand the situation better.

Regards
0
Vlad
Telerik team
answered on 06 Jul 2011, 06:31 AM
Hello,

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.

Best wishes,
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!

Tags
GridView
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Jonathan
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or