- Home
- Forum
- ASP.NET MVC
- Show columns on edit row
Show columns on edit row
Thanks for contacting Syncfusion support.
We are able to reproduce the mentioned script error. While using showcolumns method, the Grid content will refresh and the edit form will destroy. So, the script error will throw.
To achieve your requirement, use the toolbarClick event of ejGrid. This event triggers when toolbar clicked in Grid and we can get itemName in the arguments. We check the condition with ItemName and show the columns using showColumns method.
Please find the code example and sample :
|
@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowSorting() .AllowPaging() .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing();}) .ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Add); items.AddTool(ToolBarItems.Edit); items.AddTool(ToolBarItems.Delete); items.AddTool(ToolBarItems.Update); items.AddTool(ToolBarItems.Cancel); }); }) .ClientSideEvents(eve => eve.ToolbarClick("complete")) .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Visible(false).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Visible(false).Width(75).Add(); col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Visible(false).Format("{0:C}").Add(); col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Visible(false).Format("{0:MM/dd/yyyy}").Add(); col.Field("ShipCity").HeaderText("Ship City").Width(110).Visible(false).Add(); }) )
<script> function complete(args) { if (args.itemName == "Edit") { var grid = $("#Grid").ejGrid("instance"); var index = parseInt(grid.selectedRowsIndexes[0]); $('#Grid').data("ejGrid").showColumns(["ShipCity", "Freight"]); grid.selectRows(index); } </script> |
Sample: http://www.syncfusion.com/downloads/support/forum/121167/ze/Sample118577-316275400
Refer to the Help document for the toolbarClick event,
http://help.syncfusion.com/js/api/ejgrid#events:toolbarclick
Regards,
Prasanna Kumar N.S.V
By default we have the recordDoubleClick event in grid and we can show the columns in recordDoubleClick event.
Please refer to the online help documentation for recordDoubleClick event,
Document: http://help.syncfusion.com/js/api/ejgrid#events:recorddoubleclick
Note: While using showcolumns() method, the Grid content will refresh and the edit form will destroy. So, we need to use startEdit() method in recordDoubleClick event to edit the selected record.
Please refer to the code example and sample,
|
@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowSorting() .AllowPaging() .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) .ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Add); items.AddTool(ToolBarItems.Edit); items.AddTool(ToolBarItems.Delete); items.AddTool(ToolBarItems.Update); items.AddTool(ToolBarItems.Cancel); }); }) .ClientSideEvents(eve => eve.ToolbarClick("complete").RecordDoubleClick("edit")) .Columns(col => { ….
}) )
<script> function complete(args) { if (args.itemName == "Edit") { var grid = $("#FlatGrid").ejGrid("instance"); var index = parseInt(grid.selectedRowsIndexes[0]); $("#FlatGrid").data("ejGrid").showColumns(["ShipCity", "Freight"]); grid.selectRows(index); } } function edit(args) { if (!this.columnPushed) { $("#FlatGrid").data("ejGrid").showColumns(["ShipCity", "Freight"]); this.columnPushed = true;// checking if columns are already pushed this.startEdit($(this.getContentTable().find("tr")[args.rowIndex])); } } </script> |
Sample: http://www.syncfusion.com/downloads/support/forum/121167/ze/Sample_1211671543503411
Regards,
Sellappandi R
- 3 Replies
- 3 Participants
-
OM Omar Muscatello
- Nov 16, 2015 05:03 PM UTC
- Nov 18, 2015 12:54 PM UTC