Hello,
I have the following problem: I have created a grid with insert/update functionality. When I insert a row, the row is inserted in the database. The id of the row (a primary key) is updated to a new value. In the grid I don't see the new value. I see the value that was proposed by the datagrid. Why is the datagrid proposing a primary key value?When I refresh my page, the grid is refreshed. Ofcourse I don't want to do that. I want to see the changes immediately.
When I remove an item in the grid, the item is removed in the database and the grid is updated. (because when I execute the saveChanges function, I also execute the commit function) But why do I have todo this manually? I have set the property "autocommit" to true?
Below you find the code :
Html part:
@using Infragistics.Web.Mvc@model IQueryable<InfragisticsGridSample.Models.ConversieCode>
@{ViewBag.Title ="DemoGrid";}<h2>DemoGrid</h2><script src="../../Scripts/jquery-ui-1.8.11.min.js" type="text/javascript"></script><script src="../../Scripts/IG/infragistics.loader.js" type="text/javascript"></script><script type="text/javascript">function saveChanges() {$("#grid1").igGrid("saveChanges");$("#grid1").igGrid("commit");}$('#grid1').live('iggridupdatingrowadded', function() { saveChanges(); });$('#grid1').live('iggridupdatingeditrowended', function(event, ui) {if (ui.rowAdding == false) {saveChanges();}});$('#grid1').live('iggridupdatingrowdeleted', function() { saveChanges(); });$("#grid1").live("iggridupdatingdatadirty", function(event, ui) {$("#grid1").igGrid("commit");return false;});</script>@(Html.Infragistics().Loader().ScriptPath(Url.Content("~/Scripts/IG/")).CssPath(Url.Content("~/Content/css/")).Render())@(Html.Infragistics().Grid(Model).ID("grid1").PrimaryKey("Id").DataSourceUrl(Url.Action("ListConversieCodes")).UpdateUrl("EditingConversieCodes") .AutoGenerateColumns(false).Columns(column =>{column.For(x => x.Id).HeaderText("Id_Nr").DataType("number");column.For(x => x.SourceCode).HeaderText("Source Code");column.For(x => x.SourceDesc).HeaderText("Source Description");column.For(x => x.TargetCode).HeaderText("Target Code");column.For(x => x.TargetDescription).HeaderText("Target Desc");}).AutoCommit(true).Features(features =>{features.Filtering().Type(OpType.Local);features.Paging().PageSize(10).Type(OpType.Remote);features.Selection().Mode(SelectionMode.Row).MultipleSelection(true);features.RowSelectors();features.Tooltips().Visibility(TooltipsVisibility.Always);features.Updating().EnableAddRow(true).EnableAddRow(true).EnableDeleteRow(true).DeleteRowLabel("Submit").ColumnSettings(settings => {settings.ColumnSetting().ColumnKey("Id").ReadOnly(true);settings.ColumnSetting().ColumnKey("Source_Code").EditorType(ColumnEditorType.Text);settings.ColumnSetting().ColumnKey("Source_Desc").EditorType(ColumnEditorType.Text);settings.ColumnSetting().ColumnKey("Target_Code").EditorType(ColumnEditorType.Text);settings.ColumnSetting().ColumnKey("Target_Desc").EditorType(ColumnEditorType.Text);});}).DataBind().Height("360px").Width("700px").Render())
My model:public class ConversieCode { public Int32 Id { get; set; } public string CountryCode { get; set; } public string CompanyCode { get; set; } public string TypeId { get; set; } public string SourceCode { get; set; } public string SourceDesc { get; set; } public string TargetCode { get; set; } public string TargetDescription { get; set; } public DateTime UTMS { get; set; } public string UserAccount { get; set; } public string AppCodeName { get; set; } }
controller:public class HomeController : Controller{Repository _rep = new Repository();//// GET: /Home/public ActionResult DemoGrid(){List<ConversieCode> codes = _rep.ConversieCodes.ToList();return View(codes.AsQueryable());}
[GridDataSourceAction]public ActionResult ListConversieCodes(){List<ConversieCode> codes = _rep.ConversieCodes.ToList();return View(codes.AsQueryable());}
public ActionResult EditingConversieCodes() {var ds = this._rep.ConversieCodes; ViewData["GenerateCompactJSONResponse"] = false; GridModel m = new GridModel();List<Transaction<ConversieCode>> transactions = m.LoadTransactions<ConversieCode>(HttpContext.Request.Form["ig_transactions"]);foreach (Transaction<ConversieCode> t in transactions) { switch (t.type) { case "row":int id = Convert.ToInt32(t.rowId);var conversieCode = (from p in this._rep.ConversieCodes where p.Id == id select p).Single();if (!string.IsNullOrWhiteSpace(t.row.SourceCode)) {conversieCode.SourceCode = t.row.SourceCode;}if (!string.IsNullOrWhiteSpace(t.row.SourceDesc)){conversieCode.SourceDesc = t.row.SourceDesc;}
if (!string.IsNullOrWhiteSpace(t.row.TargetCode)){conversieCode.TargetCode = t.row.TargetCode;}
if (!string.IsNullOrWhiteSpace(t.row.TargetDescription)){conversieCode.TargetDescription = t.row.TargetDescription;}conversieCode.UTMS = DateTime.Now;conversieCode.UserAccount = "1000";conversieCode.AppCodeName = "Test";break; case "newrow":var newConversieCode = new ConversieCode { CountryCode = "BE",CompanyCode = "9999",SourceCode = t.row.SourceCode,SourceDesc = t.row.SourceDesc,TargetCode = t.row.TargetCode,TargetDescription = t.row.TargetDescription,TypeId = "TEST",UTMS = DateTime.Now, UserAccount = "1000",AppCodeName = "Test"};this._rep.ConversieCodes.Add(newConversieCode);break;
case "deleterow": int id2 = Convert.ToInt32(t.rowId);var deleteConversieCode = (from p in this._rep.ConversieCodes where p.Id == id2 select p).SingleOrDefault();if (deleteConversieCode != null){this._rep.ConversieCodes.Remove(deleteConversieCode);}break; } }// Save Changesthis._rep.SaveChanges();return RedirectToAction("DemoGrid");}}
DemoGrid is the action where everything happens.
At the following youtube video, you find the example that I used to build my grid.http://www.youtube.com/watch?v=aqmF6WlE7F8There we have thesame scenario. The user has to refresh his page to see an insert.
I have added the following javascript code:$(document).ajaxComplete(function (event, jqXHR, ajaxOptions, thrownError) {if (ajaxOptions.url.indexOf("EditingConversieCodes") > -1) { $("#grid1").igGrid("dataBind");}});In Firefox and Chrome the datagrid is refreshing but not in IE.In IE it crashes. I get thesame error as specified at the following url:http://es.infragistics.com/community/forums/t/62973.aspxI have the latest build.I have tested the following jquery versions:jquery-1.4.4.min.js => crash stack tracejquery-1.5.1.min.js => crash stack tracejquery-1.6.3.min.js + jquery-1.6.4.min.js => crash stack tracejquery-1.7.1.min.js + jquery-1.7.2.min.js => no crash but no update + saveChanges not triggeredjquery-1.8.0.min.js + jquery-1.8.0.min.js => crash Microsoft JScript runtime error: 'length' is null or not an object...Problem solved by using the following loader:@(Html.Infragistics().Loader().ScriptPath(http://cdn-na.infragistics.com/jquery/20122/latest/js/).CssPath(http://cdn-na.infragistics.com/jquery/20122/latest/css/).Render())