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

RadGrid dependable context menu

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MDS
Top achievements
Rank 1
MDS asked on 21 Feb 2014, 10:26 AM
Dear,

We use the rad grid with a context menu (which works fine). Now we should be
able to make the context menu dependable on the clicked row. Fe, we have a
status field in the grid. If the status field equals 'pending' we should see 3
options. If the status filed equals completed we should see 4 menu options, if
the status field is null we should see one option.

Is this achievable with the context menu? If yes, how can we do this?

Thx!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Feb 2014, 11:29 AM
Hi,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadContextMenu ID="RadContextMenu1" runat="server">
    <Items>
        <telerik:RadMenuItem Text="New">
        </telerik:RadMenuItem>
        <telerik:RadMenuItem Text="Add">
        </telerik:RadMenuItem>
        <telerik:RadMenuItem Text="Delete">
        </telerik:RadMenuItem>
        <telerik:RadMenuItem Text="Update">
        </telerik:RadMenuItem>
    </Items>
    <Targets>
        <telerik:ContextMenuControlTarget ControlID="RadGrid1" />
    </Targets>
</telerik:RadContextMenu>
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false">
    <MasterTableView DataKeyNames="status">
        <Columns>
            <telerik:GridBoundColumn DataField="status" UniqueName="status">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowContextMenu="RowContextMenu" />
    </ClientSettings>
</telerik:RadGrid>

JavaScript:
<script type="text/javascript">
    function RowContextMenu(sender, eventArgs) {
        var MasterTable = sender.get_masterTableView();
        var Rows = MasterTable.get_dataItems();
        var index = eventArgs.get_itemIndexHierarchical();
        var row = Rows[index];
        var status = row.get_cell("status").innerHTML;
        var contextmenu = $find("<%=RadContextMenu1.ClientID %>");
        if (status == "Pending") {
            contextmenu.findItemByText("New").hide();
            contextmenu.findItemByText("Add").show()
            contextmenu.findItemByText("Delete").show();
            contextmenu.findItemByText("Update").show();
        }
        else if (status == "Completed") {
            contextmenu.findItemByText("New").hide();
            contextmenu.findItemByText("Add").hide();
            contextmenu.findItemByText("Delete").hide();
            contextmenu.findItemByText("Update").show();
        }
        else {
            contextmenu.findItemByText("New").show();
            contextmenu.findItemByText("Add").show()
            contextmenu.findItemByText("Delete").show();
            contextmenu.findItemByText("Update").show();
        }
    }
</script>

Let me know if you have any concen.
Thanks,
Shinu.
0
MDS
Top achievements
Rank 1
answered on 21 Feb 2014, 02:02 PM
Thanks, this worked!
Tags
Grid
Asked by
MDS
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
MDS
Top achievements
Rank 1
Share this question
or