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

Grid Context Menu - OnSortCommand

3 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
spt3210
Top achievements
Rank 1
spt3210 asked on 04 Nov 2010, 07:34 PM
Hi,

We have a grid with CustomPaging, with 10 records per page. Sorting functionality is working fine when clicking on HeaderText. We are using OnSortCommand event to get sorted field and order as below.

FieldName = e.SortExpression, SortOrder = e.NewSortOrder

We also have context menu on the screen. When using ordering from ContextMenu SordCommand Event is not firing.

Do we need to explicitly attach event handler to any ContextMenu event?

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 09 Nov 2010, 08:24 AM
Hi spt3210,

The sort command is not firing when sorting with header context menu. You can wire an event handler for the ItemClick event of the header context menu and there put your custom logic.
protected void HeaderContextMenu_ItemClick(object sender, RadMenuEventArgs e)
        {
            if (e.Item.Text=="Sort Ascending")
            {
                //some code here
            }
        }

Let me know how this works for you and if you have any other questions.

All the best,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
spt3210
Top achievements
Rank 1
answered on 10 Nov 2010, 04:14 PM
Hi Marin,

This looks like what I need. But I am unable to find the column in this method from where it got triggered.

Is there a way to find out?

Thanks!
0
Marin
Telerik team
answered on 12 Nov 2010, 05:09 PM
Hi spt3210,

Yes, there is a way:
protected void HeaderContextMenu_ItemClick(object sender, RadMenuEventArgs e)
        {
            if (e.Item.Text=="Sort Ascending")
            {
                //retrieve the column name
                string columnName = e.Item.Attributes["ColumnName"];
                //get instance to the column from the respective GridTableView
                GridColumn gridColumn = RadGrid1.MasterTableView.GetColumnSafe(columnName);
            }
        }

First we retrieve the column name from the attributes collection of the menu item and then we get and instance to that column.

Hope this helps, let me know if you have any other questions.

Greetings,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
spt3210
Top achievements
Rank 1
Answers by
Marin
Telerik team
spt3210
Top achievements
Rank 1
Share this question
or