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

RadGrid - How to know if HeaderMenu is displayed for MasterTable or Detail Table

6 Answers 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tushar
Top achievements
Rank 1
Tushar asked on 19 Jun 2014, 09:01 AM
Hi,
I have added some custom header menus (e.g Export to CSV) to my RadGrid. They work fine with the MasterTable.

But when I right click on Detail Table header, same menus are displayed as master table.

I want to hide my custom menu when user right clicks Detail Table header.

I tried to check in HeaderContextMenu.OnClientShowing client event, but I am not able to get any property to confirm if it is Master Table or Detail Table.

Is there a way to Identify if header menu is being displayed for Master Table or Detail Table?

Thanks!!

6 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 23 Jun 2014, 07:02 AM
Hi Tushar,

You can use the OnHeaderMenuShowing client event to identify the table for which contextmenu is opening.

ASPX:
<ClientSettings >
    <ClientEvents OnHeaderMenuShowing="HeaderMenuShowing" />
</ClientSettings>

JS:
<script type="text/javascript">
function HeaderMenuShowing(sender, eventArgs) {   
  var tableName = eventArgs._gridColumn._owner._data.Name;
  alert(tableName);      
 }
</script>

Thanks,
Princy
0
Tushar
Top achievements
Rank 1
answered on 07 Jul 2014, 10:23 AM
Thanks Princy, I will try this.
0
Tushar
Top achievements
Rank 1
answered on 16 Jul 2014, 02:39 PM
Hi Princy,
Thanks for your reply. But you solution didnt work. I was not able to find _gridColumn. Is there any other way?
0
Princy
Top achievements
Rank 1
answered on 17 Jul 2014, 04:57 AM
Hi Tushar,

The code was working fine at my end. Can you make sure you have given the Name property for your MasterTable and DetailTable. Please try the following code snippet as well, if this doesn't help, can you provide your code snippet and the version you are using.

JS:
<script type="text/javascript">
    function HeaderMenuShowing(sender, eventArgs) {   
        alert(eventArgs.get_gridColumn()._owner._data.Name);
    }  
</script>

Thanks,
Princy
0
Tushar
Top achievements
Rank 1
answered on 17 Jul 2014, 08:04 AM
Hi Princy,
Please see my code below.

I am getting this exception when checked in firefox:
message:"args.get_gridColumn is not a function"

I am using ASP.NET AJAX controls version 2014.2.618.45

<script type="text/javascript">
    function headerMenuShowing(sender, args) {
        var tableName = args.get_gridColumn()._owner._data.Name;
        var parent = sender.get_parent();
        var masterTable = parent.get_masterTableView();
        var dataCount = masterTable.get_dataItems().length;
    }


</script>

<div style="height:400px">
    <telerik:RadGrid id="RadGrid1" Height="90%" runat="server" ClientSettings-Scrolling-AllowScroll="true"
        autogeneratecolumns="false" onneeddatasource="RadGrid1_NeedDataSource" 
        OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
        enableheadercontextmenu="true" allowfilteringbycolumn="true"
        MasterTableView-HierarchyLoadMode="Client">
        <HeaderContextMenu OnClientShowing="headerMenuShowing">
        </HeaderContextMenu>
        <MasterTableView TableLayout="Fixed" Name="Master">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID" HeaderStyle-Width="100px" />
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name1" UniqueName="Name1" HeaderStyle-Width="200px" />
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name2" UniqueName="Name2" HeaderStyle-Width="100px" />
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name3" UniqueName="Name3" HeaderStyle-Width="200px" />
            </Columns>
            <DetailTables>
                <telerik:GridTableView DataKeyNames="Message1" AllowFilteringByColumn="true" Name="childGrid">
                    <Columns>
                        <telerik:GridBoundColumn DataField="Message1" HeaderText="Message1" UniqueName="Message1" HeaderStyle-Width="150px" />
                        <telerik:GridBoundColumn DataField="Message2" HeaderText="Message2" UniqueName="Message2" HeaderStyle-Width="150px" />
                        <telerik:GridBoundColumn DataField="Message3" HeaderText="Message3" UniqueName="Message3" HeaderStyle-Width="150px" />
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
        </MasterTableView>
    </telerik:RadGrid>
</div>

Thanks!!




0
Princy
Top achievements
Rank 1
answered on 18 Jul 2014, 05:14 AM
Hi Tushar,

In my above code snippet I used ClientSettings -> ClientEvents -> OnHeaderMenuShowing. If you are using HeaderContextMenu -> OnClientShowing, please try the following codes snippet:

JS:
args._targetElement.parentNode.parentNode.parentNode.control._data.Name

Thanks,
Princy
Tags
Grid
Asked by
Tushar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Tushar
Top achievements
Rank 1
Share this question
or