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

Ajax Grid has ShowColumnSortIndexes ?

1 Answer 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kelmen
Top achievements
Rank 1
Kelmen asked on 22 Dec 2014, 07:25 AM
doing multi-columns sorting, this property ShowColumnSortIndexes seems to be for WPF library, does ajax Grid has similar feature/prop?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 24 Dec 2014, 05:53 PM
Hello Kelmen,

RadGrid does not have such built-in functionality, but you can use the following approach to include the sort index in the column headers:
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true"
    OnPreRender="RadGrid1_PreRender" MasterTableView-AllowMultiColumnSorting="true"
     AllowSorting="true">
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("FirstName", typeof(string));
    table.Columns.Add("LastName", typeof(string));
    table.Columns.Add("Age", typeof(int));
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("BoolValue", typeof(Boolean));
    for (int i = 0; i < 55; i++)
    {
        table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
    }
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    GridHeaderItem headerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
    int sortIndex = 1;
    foreach (GridSortExpression expression in RadGrid1.MasterTableView.SortExpressions)
    {
        foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)
        {
            if (column is IGridDataColumn)
            {
                if (expression.FieldName == (column as IGridDataColumn).GetActiveDataField())
                {
                    TableCell cell = headerItem[column.UniqueName];
                    Literal literal = new Literal();
                    literal.Text = sortIndex.ToString();
                    cell.Controls.Add(literal);
                }
            }
        }
 
        sortIndex++;
    }
}

You can also use different control for the index and apply custom styles to it.


Best Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Kelmen
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or