Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
105
iggrid not updating after saveChanges
posted

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 Changes
this._rep.SaveChanges();
return RedirectToAction("DemoGrid");
}
}

DemoGrid is the action where everything happens.

 

Parents Reply Children
No Data