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

How to track column name and type of operation performed on RadGrid with header context menu features ?

6 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ankesh Bharti
Top achievements
Rank 1
Ankesh Bharti asked on 01 Jun 2010, 06:02 AM
Hi,

According to some requirement in my project , I want to track column name and type of operation performed on that column through header context menu options. For Example :-  In my grid, I have three columns named 'ProductID','ProductName' & 'CategoryID'. When I opened context menu by clicking right click on 'CategoryID' column in  header of grid, and select 'Sort Ascending' or 'Group By'. Then Gird get sorted with 'CategoryID' in ascending order or Grid get grouped by column 'CategoryID'. Then finally I want to track the Column 'CtaegoryID' and operation 'Sort Ascending' or 'Group By' and want to save these two information in some string type global variables on completion of these operations.

Please provide me solution for this. Thanks a lot in advance for this solution.


Regards,
Ankesh Bharti

6 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 04 Jun 2010, 07:58 AM
Hi Ankesh,

The best option in this case is to subscribe to the ItemCommand server side event handler. This would give you a chance to track each operation, and get additional information on it via the command arguments.
I hope this gets you started properly.

Sincerely yours,
Yavor
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
J2K
Top achievements
Rank 1
answered on 02 Dec 2010, 10:14 AM
Was this issue ever solved?  We have the identical requirement of tracking/capturing what users are doing with the very convenient header contextmenu.  The suggestion of capturing in the server itemcommand however seems to be a dead end as we can't detect that the command is firing on the server side when the header context menu is used.
0
Tsvetina
Telerik team
answered on 07 Dec 2010, 09:28 AM
Hello,

You can detect whether the HeaderContextMenu fired the command by checking the e.CommandSource value, which would point to the GridHeaderItem in case the header context menu was used.

Greetings,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
K
Top achievements
Rank 1
answered on 15 Mar 2011, 11:14 PM
Hi,

I think there is something else missing here.   It appears as if no server side events are firing.  Or, at least, the page.load event isn't being hit.  

Here is the grid I'm testing with
<telerik:RadGrid ID="RadGrid1" runat="server"  AutoGenerateColumns="false" width="400px">
           
         <MasterTableView IsFilterItemExpanded="true"  ShowHeadersWhenNoRecords="true" EnableHeaderContextMenu="true"  >
             <NoRecordsTemplate />
             <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />
             <Columns>
                 <telerik:GridTemplateColumn uniquename="Column1" HeaderText="Column 1" DataField="Column1" >
                     <ItemTemplate>
                     </ItemTemplate>
                     <FooterStyle Width="120px" />  
                     <HeaderStyle Width="120px"/>  
                     <ItemStyle Width="100%" />  
                 </telerik:GridTemplateColumn>
                 <telerik:GridTemplateColumn uniquename="Column2"  HeaderText="Column 2" DataField="Column2">
                     <ItemTemplate>
                     </ItemTemplate>
                     <FooterStyle Width="120px" />  
                     <HeaderStyle Width="120px" />  
                     <ItemStyle Width="100%" />  
                 </telerik:GridTemplateColumn>
                 <telerik:GridTemplateColumn uniquename="Column3"  HeaderText="Column 3" DataField="Column2">
                     <ItemTemplate>
                     </ItemTemplate>
                     <FooterStyle Width="120px" />  
                     <HeaderStyle Width="120px" />  
                     <ItemStyle Width="100%" />  
                 </telerik:GridTemplateColumn>
            </Columns>
         </MasterTableView>

And this is the code behind,  I've removed the group by items in the menu because there aren't any group by expressions

Protected Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand 
    Me.Label1.Text = e.CommandName & " " & e.CommandSource 
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    Me.RadScriptManager1.RegisterPostBackControl(Me.RadGrid1) 
    AddHandler Me.RadGrid1.HeaderContextMenu.PreRender, (AddressOf Me.HeaderContextMenu_PreRender) 
    Me.RadGrid1.DataSource = String.Empty 
    Me.RadGrid1.Rebind() 
End Sub
Protected Sub HeaderContextMenu_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) 
    Dim menu As RadContextMenu = Me.RadGrid1.HeaderContextMenu 
    For Each item As RadMenuItem In menu.Items 
        If item.Text <> "Columns" Then
            item.Target = ""
            item.Visible = False
        End If
    Next
End Sub

0
Tsvetina
Telerik team
answered on 18 Mar 2011, 11:41 AM
Hi,

The grid that you are testing with only has the columns menu which does not do any actions which would cause page postback. That is why your server-side events are not executed. The header context menu uses client script to hide columns.

Once I showed the sorting options in the menu and used them, the grid did a postback and both Page_Load and ItemCommand events were hit.

Regards,
Tsvetina
the Telerik team
0
K
Top achievements
Rank 1
answered on 23 Mar 2011, 06:31 PM
Thanks,

I used the information here: Getting familiar with client-side API to get the name of the columns when they were hidden or shown.

Specifically functions calling eventArgs.get_gridColumn().get_uniqueName()  and hooked to the ClientEvents-OnColumnHiding and ClientEvents-OnColumnShown events in the clientsettings  element.
Tags
Grid
Asked by
Ankesh Bharti
Top achievements
Rank 1
Answers by
Yavor
Telerik team
J2K
Top achievements
Rank 1
Tsvetina
Telerik team
K
Top achievements
Rank 1
Share this question
or