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

RadGrid 3 level hierarchy Sorting by Up Down Arrow

1 Answer 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Mohammed asked on 06 Feb 2015, 08:12 PM
Hi,
Our company is in the process evaluating Telerik control to buy your product. We were testing some key functionalities in your trial version. One of the main requirement we came across is Sorting(either by drag n drop or by move up down arrow). We tried with the move up and down arrow by we couldn't get it work.
I followed one of the blog post http://www.telerik.com/forums/radgrid-rows-sorting-move-up-and-move-down-button . Im using move up down arrow method in RADGRID Hierarchy Grid(Three level). I have attached the screen shot of what I'm trying to do. I need to able to sort with in each hierarchy list. Please let me know if your product can do this function.

Thanks
Merchant

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 11 Feb 2015, 11:19 AM
Hi Mohammed,

RadGrid could be used for achieving such behavior, but you will have to handle the sorting manually by creating sort expression for the nested GridTableViews.

For the buttons (with the arrows) you could use GridTemplateColumn, where you can place both of the buttons in the ItemTemplate. Then, you will have to handle the server-side OnClick event and created the expressions.

Following is a very basic example demonstrating such implementation:
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn HeaderText="Sorting">
                <ItemTemplate>
                    <telerik:RadButton ID="RadButton1" runat="server" Text="Asc" OnClick="RadButton1_Click"></telerik:RadButton>
                    <telerik:RadButton ID="RadButton2" runat="server" Text="Desc" OnClick="RadButton2_Click"></telerik:RadButton>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
        <DetailTables>
            <telerik:GridTableView>
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("Column1", typeof(string));
    table.Columns.Add("Column2", typeof(string));
    table.Columns.Add("Column3", typeof(string));
    table.Columns.Add("Column4", typeof(string));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add("value1" + i, "value2" + i, "value3" + i, "value4" + i);
    }
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 
}
protected void RadButton1_Click(object sender, EventArgs e)
{
    GridDataItem parentItem = (sender as RadButton).NamingContainer as GridDataItem;
    if (parentItem.HasChildItems)
    {
        GridTableView nestedTableView = (parentItem.ChildItem as GridNestedViewItem).NestedTableViews[0];
        GridSortExpression expression = new GridSortExpression();
        expression.FieldName = "Column2";
        expression.SortOrder = GridSortOrder.Ascending;
        nestedTableView.SortExpressions.AddSortExpression(expression);
        nestedTableView.Rebind();
    }
}
 
protected void RadButton2_Click(object sender, EventArgs e)
{
    GridDataItem parentItem = (sender as RadButton).NamingContainer as GridDataItem;
    if (parentItem.HasChildItems)
    {
        GridTableView nestedTableView = (parentItem.ChildItem as GridNestedViewItem).NestedTableViews[0];
        GridSortExpression expression = new GridSortExpression();
        expression.FieldName = "Column2";
        expression.SortOrder = GridSortOrder.Descending;
        nestedTableView.SortExpressions.AddSortExpression(expression);
        nestedTableView.Rebind();
    }
}

As you can notice, within the OnClick event handler we are creating the sort expression by a given data field.

Hope this helps.


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
Mohammed
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or