Hi there ,
i'd like (i guess) something easy but still enough hard for me :)
I'm looking for sorting a raadgrid by clicking on Header Columns.
This is my radgrid :
Adding SortExpression? How could i do it in code behind ?
Thx in advance :)
J-Marie P.
Edit :
Its seems sorting work for the X rows already fill in datasource. ( excepted Imagecolumn and hyperlink colum )
I need to sort on All of my data ,i already have a GetData retriveing without sortedField.So i have to do a GetDataByField() to retrive X first rows then each time i click on header recall this method and give me the X good rows :)
How could i catch click on header ?
i'd like (i guess) something easy but still enough hard for me :)
I'm looking for sorting a raadgrid by clicking on Header Columns.
This is my radgrid :
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TodoGrid.ascx.cs" Inherits="CSN.Phenix.UI.Web.Foundation.CommonControls.TodoList.TodoGrid" %><telerik:RadGrid ID="rg" runat="server" AutoGenerateColumns="false" GridLines="None" AllowSorting="true" AllowPaging="true" AllowCustomPaging="true" PagerStyle-Mode="NextPrevAndNumeric" PagerStyle-NextPageText="Next" PagerStyle-PrevPageText="Previous" PageSize="10" PagerStyle-Position="Bottom" OnNeedDataSource="rg_NeedDataSource" OnItemDataBound="rg_ItemDataBound" meta:resourcekey="resourceRgTodo" > <MasterTableView DataKeyNames="Id" DataMember="Id"> </MasterTableView></telerik:RadGrid>I'm generating DataColumn dynamically in code behind :
What could i need to add for sorting them ?private void CreateGridColumnsGeneric() { int hiddenColumnsCount = 0; this.specialColumns = new List<SpecialColumn>(); foreach (DataColumn dataColumn in this.DataSourceObject.GetColumns(this.TabId)) { if (dataColumn.ColumnName == PhxTools.TodoList.SPECIAL_DISPLAY_COLUMN_NAME) { // colonne qui permet de savoir si l'on doit afficher la ligne d'une certaine manière // on conserve la colonne pour pouvoir gérer l'affichage de la ligne correctement this.specialColumns.Add(new SpecialColumn() { ColumnName = PhxTools.TodoList.SPECIAL_DISPLAY_COLUMN_NAME, ColumnType = "Special", ColumnDisplayIndex = dataColumn.Ordinal - hiddenColumnsCount }); } else if (dataColumn.ExtendedProperties[PhxTools.TodoList.TODO_GRID_COLUMN_HIDDEN] == null) { GridColumn column = null; if (dataColumn.ExtendedProperties[PhxTools.TodoList.TODO_GRID_COLUMN_TYPE] != null) { string colType = dataColumn.ExtendedProperties[PhxTools.TodoList.TODO_GRID_COLUMN_TYPE].ToString(); // les colonnes "hyperliens" if (colType == PhxTools.TodoList.TODO_GRID_COLUMN_HYPERLINK) column = CreateHyperLinkColumn(dataColumn); // les colonnes "images" else if (colType == PhxTools.TodoList.TODO_GRID_COLUMN_IMAGE) { // on conserve la colonne pour pouvoir gérer l'affichage de la ligne correctement this.specialColumns.Add(new SpecialColumn() { ColumnName = dataColumn.ColumnName, ColumnType = PhxTools.TodoList.TODO_GRID_COLUMN_IMAGE, ColumnDisplayIndex = dataColumn.Ordinal - hiddenColumnsCount }); column = CreateImageColumn(dataColumn); } } else { // les autres colonnes : on ne fait que du binding column = CreateColumn(dataColumn); } if (dataColumn.ExtendedProperties[PhxTools.TodoList.COLUMN_SORT_EXPRESSION] != null) column.SortExpression = dataColumn.ExtendedProperties[PhxTools.TodoList.COLUMN_SORT_EXPRESSION].ToString(); else column.SortExpression = null; column.HeaderText = dataColumn.ColumnName; if (dataColumn.ExtendedProperties[PhxTools.TodoList.TODO_COLUMN_DISPLAY_NAME] != null) column.HeaderText = dataColumn.ExtendedProperties[PhxTools.TodoList.TODO_COLUMN_DISPLAY_NAME].ToString(); if (column != null) rg.Columns.Add(column); } else { ++hiddenColumnsCount; } } }Adding SortExpression? How could i do it in code behind ?
Thx in advance :)
J-Marie P.
Edit :
Its seems sorting work for the X rows already fill in datasource. ( excepted Imagecolumn and hyperlink colum )
I need to sort on All of my data ,i already have a GetData retriveing without sortedField.So i have to do a GetDataByField() to retrive X first rows then each time i click on header recall this method and give me the X good rows :)
How could i catch click on header ?