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

Batch Edit Grid with Popup Option

1 Answer 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JV
Top achievements
Rank 1
JV asked on 15 Dec 2014, 05:36 AM
Hello,

I am evaluating RadGrid for one of my project. For this we are using RADGrid with EditMode="Batch". My client want requirement that "A right mouse click
on “Add New Record” would bring up a menu where you can choose the Grid or the popup window." (as in attached image) . If you choose Grid then it’s in the rad grid. If you choose popup then it would bring up a Popup window for data entry.

I want to know that Whether both option of Grid add/Edit and Popup add/Edit is possible in Batch Edit type grid.
Is it possible to do this? If it is there, then please share a sample demo code for this.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 17 Dec 2014, 10:06 AM
Hello,

This is a highly complex scenario and RadGrid could not provide any of the requirements out-of-the-box. 

Nevertheless, following is a simple example demonstrating how to add a context menu on the "Add new record" buttons:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function showContextMenu(e) {
            var contextMenu = $find("<%=AddRecordMenu.ClientID%>");
            contextMenu.show(e);
        }
 
        function itemClicked(sender, args) {
            if (args.get_item().get_value() == "1") {
                var grid = $find("<%=RadGrid1.ClientID%>");
                var masterTable = grid.get_masterTableView();
                var batchManager = grid.get_batchEditingManager();
                batchManager.addNewRecord(masterTable);
            }
            else {
                // your custom logic
            }
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadContextMenu runat="server" ID="AddRecordMenu" OnClientItemClicked="itemClicked">
    <Items>
        <telerik:RadMenuItem Text="Add in grid" Value="1"></telerik:RadMenuItem>
        <telerik:RadMenuItem Text="Add in popup" Value="2"></telerik:RadMenuItem>
    </Items>
</telerik:RadContextMenu>
 
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnPreRender="RadGrid1_PreRender">     
    <MasterTableView EditMode="Batch" CommandItemDisplay="Top">
    </MasterTableView>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("FirstName", typeof(string));
    table.Columns.Add("LastName", typeof(string));
    table.Columns.Add("Age", typeof(int));
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("BoolValue", typeof(Boolean));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
    }
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    GridCommandItem commandItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0] as GridCommandItem;
    Button addButton = commandItem.FindControl("AddNewRecordButton") as Button;
    LinkButton linkAddButton = commandItem.FindControl("InitInsertButton") as LinkButton;
    addButton.Attributes.Add("oncontextmenu", "showContextMenu(event); return false;");
    linkAddButton.Attributes.Add("oncontextmenu", "showContextMenu(event); return false;");
}

As for the popup edit form, this is not supported scenario and the entire implementation should be handled by the developer.

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