I thought I was about done implementing all of the features that I needed to do for this grid, but I have stumbled across one last issue.
I have my grid finally working for add, edit, and delete functionality. Except, that if I click a row that isn't the first row (let's say it's the second row), and click the Edit toolbar icon, the row become editable, but the fields are filled with the values from the first row! I have attached an image file for you to see.
Why is this happening? I would like the Edit function to show the actual values from that row. Any help?
Cindy
Here is my grid code:
@using SyncfusionMvcApplication3.Models
@model IEnumerable<OrdersView>
@(Html.EJ().DataManager("Customers").Json((IEnumerable<Customer>)ViewBag.childCustomers))
@(Html.EJ().Grid<OrdersView>("FlatGrid")
.Datasource(Model)
.AllowScrolling()
.AllowPaging() /*Paging Enabled*/
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width(80).AllowEditing(true).Add();
col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();
})
.ClientSideEvents(eve => { eve.BeginEdit("beginedit").ActionComplete("actioncomplete"); })
.ChildGrid(child =>
{
child.Datasource(ds => ds.URL(@Url.Action("ChildDataSource"))
.InsertURL(@Url.Action("ChildInsert"))
.UpdateURL(@Url.Action("Update"))
.RemoveURL(@Url.Action("Delete"))
.Adaptor(AdaptorType.UrlAdaptor))
.QueryString("OrderID")
.EditSettings(edit =>
{
edit.AllowAdding().AllowDeleting().AllowEditing()
.RowPosition(RowPosition.Top)
.ShowDeleteConfirmDialog(true)
;
})
.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(evnt => evnt.ActionComplete("actionComplete"))
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Visible(false).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("ProductName").HeaderText("Product Name").Width(120).Add();
col.Field("Quantity").Width(100).Add();
col.Field("ExtendedPrice").Width(100).Add();
});
})
)
<script type="text/javascript">
function actionComplete(args) {
if (args.requestType === "add" || args.requestType === "beginedit") {
var $edit = $("form[id$='EditForm']");
$edit.on("keypress keyup keydown", preventEnterKey);
};
};
function preventEnterKey(e) {
if (e.which === 13 || e.which === 169) {
e.preventDefault();
return false;
};
return true;
}
</script>