We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

GGC Sorting

I am using Grid Grouping Control (GGC) and I want sorting should work in two modes,

1. Sorting on values
2. Sorting on display text

Background:

1. System has flag say “Sorting on value” and “Sorting on display text”.
2. User can chose among these flags for sorting behaviour.
3. System has some functionality where display texts and underlying values for columns may differ.
4. All columns (aprox. 300) are bound and unbound columns.
5. Display text for cell is been changed based on some logic in “QueryCellStyleInfo” using e.Style.Text = “Some Value”

Full detail is been attached in word doc.



GGC Sorting.zip

6 Replies

AD Administrator Syncfusion Team February 20, 2008 09:17 PM UTC

Hi Amol,

Sort by ValueMember:
>>>>>>>>>>>>>>>>>>>>
By default, GroupingGrid sort the column by its value member. Please try this code to sort the column in a grid.

this.gridGroupingControl1.TableDescriptor.SortedColumns.Add( new SortColumnDescriptor("ColumnName", ListSortDirection.Ascending) );

Sort by DisplayMember:
>>>>>>>>>>>>>>>>>>>>
Please refer to the below forum thread which implements a solution for sorting a column by its display member instead of the value member of the column. Let us know if you need any further assistance.

http://www.syncfusion.com/support/forums/message.aspx?MessageID=39048

Best Regards,
Haneef



AM Amol February 21, 2008 01:16 PM UTC

Hi Haneef,

Thanks, for your quick response. Given solution is not suitable for my requirement. Please see points listed below,

1. I already have parent and child table in GGC
2. User can add/delete rows to GGC
3. GGC is bound to entity
4. I have lot much other functionality on GGC which may break by adding one more child table to table descriptor
5. More than 300 columns (bound & unbound) need to implement this functionality

Do you have some other way to achieve sorting on display text…?

Thanks,
Amol




AM Amol February 22, 2008 03:20 PM UTC

Thanks once again Haneef,

I really appreciate you guy’s replies so promptly.

I did the same thing for unbound columns as I can change values for unbound columns in QueryValue. It works fine …!

I have bound columns and putting additional unbound columns for each bound column would be overhead on system as I mentioned we have more than 300 columns (unbound – 100, bound – 200).

I tried with custom comparer but in vain as I can access only values using custom comparer.

Can we achieve this without using additional unbound columns, another child table etc…

What I am asking if is not possible except given solution then please convey this as I have to tell business in advance….

Is Clay enjoying his vacation any updates…?









AD Administrator Syncfusion Team February 22, 2008 04:02 PM UTC

Hi Amol,

One way you can do this by adding the unbound column to grid. In that column, you need to maintain displaytext information of all columns in a GridRecord. And also you can add a custom IComparer to the SortColumnDescriptor for this unbound column to sort column based on displaytext. This can be done by setting the Comparer property on the SortColumnDescriptor. In the custom IComparer object, you can sort based on any criteria you want. Here are the codes for your reference:

//Maintain the displaytext of all columns in GridRecord.
void gridGroupingControl1_QueryValue(object sender, FieldValueEventArgs e)
{
if (e.Field != null
&& e.Field.Name == "DisplaySort"
&& e.Record != null)
{
int RowIndex = e.Record.GetRowIndex();
DataRowView row = e.Record.GetData() as DataRowView;
DataRow rowCopy = row.Row.Table.NewRow();
rowCopy.ItemArray = row.Row.ItemArray;

GridGroupingControl GroupingGrid = sender as GridGroupingControl;

GridTableDescriptor td = e.TableDescriptor as GridTableDescriptor;
foreach (GridColumnDescriptor column in td.Columns)
{
if ( column.Name != "DisplaySort")
{
int field = td.NameToField(column.Name);
int colIndex = td.FieldToColIndex(field);
GridTableCellStyleInfo style = GroupingGrid.Table.GetTableCellStyle(RowIndex, colIndex);
rowCopy[column.MappingName] = style.FormattedText;
}
}
e.Value = rowCopy;
}
}
}

Please refer to the attached sample for implementation.
http://websamples.syncfusion.com/samples/Grid.Windows/I41636/RecordSortingbyDisplayMemberSample.zip

Best regards,
Haneef



AM Amol February 25, 2008 01:18 PM UTC

Thanks,

I am getting compile time error for,

int RowIndex = e.Record.GetRowIndex();

'Syncfusion.Grouping.Record' does not contain a definition for 'GetRowIndex'

Any other way to get row index...?

Regards,
Amol




AD Administrator Syncfusion Team February 25, 2008 02:48 PM UTC

Hi Amol,

Please try this code:

int RowIndex = e.Record.Engine.Table.NestedDisplayElements.IndexOf(e.Record );

Best regards,
Haneef


Loader.
Live Chat Icon For mobile
Up arrow icon