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

How to Show Sort icon

Hi,

We are using Syncfusion grid for VS.NET 2003.
We have written codes to sort and display the records based on the header in which user clicks. We want to show sort icon (triangle) in the grid header once the user clicks on the header.

Eg : We have a grid with col A, Col B, Col C.

If the user clicks on Col A, the relavent (asc, dec) sort icon should be shown in the header with the colun name

Thanks
R.Vasanth

1 Reply

AD Administrator Syncfusion Team February 19, 2007 03:34 PM UTC

Hi Vasanth,

Sorting is directly supported in a GridDataBoundGrid based on the grids through the underlying datatable. For GridControl based grids, the GridControlSort ( \Syncfusion\Essential Studio\4.4.0.49\Windows\Grid.Windows\Samples\FeatureSamples\GridControlSort )browser sample will show you how to add header-click sorting to your grid. The header cell draws a sort icon to indicate that the column has been sorted in a particular direction.

There is an inbuilt class, the GridSortColumnHeaderCellModel which, by passing an instance through the CellModels.Add function creates a CellType.

this.gridControl1.CellModels.Add("ColumnHeaderCell", new GridSortColumnHeaderCellModel(this.gridControl1.Model));
this.gridControl1[0, col].CellType = "ColumnHeaderCell";

The direction of the sort icon can be controlled by passing the Ascending or Descending options of the ListSortDirection enumerator through the tag property of the grid.

ListSortDirection dir = ListSortDirection.Ascending;
this.gridControl1[0, col].Tag = dir;

Sorting is done by the Data.SortByColumn function. There are 5 overloads for this function. It also enables comparison through the custom comparer.

this.gridControl1.Data.SortByColumn(col, dir, new FormulaComparer());

A custom comparer class which, derives the IComparer is used to compare the formula values and not the formulas. The FormulaTag.Text property has the formula result and it is used to compare two cells.

Here is a sample.
GridControlSort.zip

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon