Hello,
1. I would like to ask how to save data iggrid the database. Using the "Save" button by image. And I use MS SQL.
2. I would like to ask how to keep sesion of the new row and data edit on iggrid form pending. I use Ajax to retrieve data display.
Example
2.1 I add data new row at Product ID = 12
2.2 I click "Done" button. But iggrid not add row Product ID = 12.
Thank you.Sulada
Hello Sulada,
Thank you for posting in our community.
There is a working sample in our Online Samples Browser illustrating how igGrid Updating feature communicates with Grid MVC Helper wrapper to persist changes on the server. The igGrid Updating feature uses transactions to log any changes made to the grid. There transactions are kept locally in the browser until the igGrid.saveChanges API method is called to send a POST request to the Url indicated by the igGrid. updateUrl option. On the server these transactions should be parsed and processed and the igGrid MVC Helper wrapper greatly simplifies this task. The OrdersSaveData controller method is uses a GridModel.LoadTransactions<T> to desterilize the changes from the grid and process them. Use the grid to add, edit or delete single or multiple records. In order to send changes on the server with Ajax call the "Save Changes" button should be pressed.
[GridDataSourceAction] [ActionName("datatable-binding")] public ActionResult BasicMvcHelper() { DataTable customers = this.GetCustomers; NameValueCollection queryString = HttpUtility.ParseQueryString(Request.QueryString.ToString()); // check the query string for sorting expressions List<SortExpression> sortExpressions = BuildSortExpressions(queryString, "sort"); DataView dv = customers.DefaultView; if (sortExpressions.Count > 0) { String sortExpression = ""; foreach (SortExpression expr in sortExpressions) { sortExpression += expr.Key + " " + (expr.Mode == SortMode.Ascending ? "asc" : "desc") + ","; } dv.Sort = sortExpression.Substring(0, sortExpression.Length - 1); } return View("datatable-binding", dv.ToTable()); } public ActionResult OrdersSaveData() { GridModel gridModel = new GridModel(); List<Transaction<Order>> transactions = gridModel.LoadTransactions<Order>(HttpContext.Request.Form["ig_transactions"]); var orders = RepositoryFactory.GetOrderRepository(); foreach (Transaction<Order> t in transactions) { if (t.type == "newrow") { orders.Add(t.row); } else if (t.type == "deleterow") { orders.Delete(o => o.OrderID == Int32.Parse(t.rowId)); } else if (t.type == "row") { var order = (from o in orders.Get() where o.OrderID == Int32.Parse(t.rowId) select o).Single(); if (t.row.OrderDate != null) { order.OrderDate = t.row.OrderDate; } if (t.row.TotalPrice != null) { order.TotalPrice = t.row.TotalPrice; } if (t.row.TotalItems != null) { order.TotalItems = t.row.TotalItems; } if (t.row.CustomerID != null) { order.CustomerID = t.row.CustomerID; } if (t.row.ShipAddress != null) { order.ShipAddress = t.row.ShipAddress; } orders.Update(order, o => o.OrderID == Int32.Parse(t.rowId)); } } orders.Save(); JsonResult result = new JsonResult(); Dictionary<string, bool> response = new Dictionary<string, bool>(); response.Add("Success", true); result.Data = response; return result; }
[GridDataSourceAction] [ActionName("datatable-binding")] public ActionResult BasicMvcHelper() { DataTable customers = this.GetCustomers; NameValueCollection queryString = HttpUtility.ParseQueryString(Request.QueryString.ToString()); // check the query string for sorting expressions List<SortExpression> sortExpressions = BuildSortExpressions(queryString, "sort"); DataView dv = customers.DefaultView; if (sortExpressions.Count > 0) { String sortExpression = ""; foreach (SortExpression expr in sortExpressions) { sortExpression += expr.Key + " " + (expr.Mode == SortMode.Ascending ? "asc" : "desc") + ","; } dv.Sort = sortExpression.Substring(0, sortExpression.Length - 1); } return View("datatable-binding", dv.ToTable()); }
public ActionResult OrdersSaveData() { GridModel gridModel = new GridModel(); List<Transaction<Order>> transactions = gridModel.LoadTransactions<Order>(HttpContext.Request.Form["ig_transactions"]); var orders = RepositoryFactory.GetOrderRepository(); foreach (Transaction<Order> t in transactions) { if (t.type == "newrow") { orders.Add(t.row); } else if (t.type == "deleterow") { orders.Delete(o => o.OrderID == Int32.Parse(t.rowId)); } else if (t.type == "row") { var order = (from o in orders.Get() where o.OrderID == Int32.Parse(t.rowId) select o).Single(); if (t.row.OrderDate != null) { order.OrderDate = t.row.OrderDate; } if (t.row.TotalPrice != null) { order.TotalPrice = t.row.TotalPrice; } if (t.row.TotalItems != null) { order.TotalItems = t.row.TotalItems; } if (t.row.CustomerID != null) { order.CustomerID = t.row.CustomerID; } if (t.row.ShipAddress != null) { order.ShipAddress = t.row.ShipAddress; } orders.Update(order, o => o.OrderID == Int32.Parse(t.rowId)); } } orders.Save(); JsonResult result = new JsonResult(); Dictionary<string, bool> response = new Dictionary<string, bool>(); response.Add("Success", true); result.Data = response; return result; }
Working sample could be find at the following link:
http://www.igniteui.com/grid/basic-editing
Please have a look at this sample and let me know if you have any additional questions regarding this matter.
Hello Vasya Kacheshmarova,
Thank you for your advice and example. I put it to apply to my work.
Thank you.
Sulada