ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Using different Key than 'Id' in Grid Crud operation
Title:
B
I
{code}
?
I am using awesome mvc grid control for popup adding functionality. My View looks like: @(Html.Awe().Grid("DesignationGrid") .Mod(o => o.PageInfo().ColumnsSelector()) .Url(Url.Action("GetGridItems", "Designation")) .Parent("txtSearch", "search") .Height(350) .Columns( new Column { Bind = "DesignationID" }, new Column { Bind = "Name" }, new Column { Bind = "Name_OL1" }, new Column { Bind = "Name_OL2" }, new Column { ClientFormat = SalesARM.Web.UI.Utils.GridUtils.EditFormatForGrid("DesignationGrid", "DesignationID"), Width = 50 }, new Column { ClientFormat = SalesARM.Web.UI.Utils.GridUtils.DeleteFormatForGrid("DesignationGrid", "DesignationID"), Width = 50 })) and controller looks like : public ActionResult GetGridItems(GridParams g, string search) { search = (search ?? "").ToLower(); List<Designation> designationList = null; ApplicationExceptionHandler.Handle(() => { ServiceProcessComponent.Use<MasterDataServiceClient>(desiginationService => { designationList = desiginationService.GetAllDesignations(OrganisationID).OrderBy(x => x.DesignationID).ToList(); }); }); var items = designationList.Where(o => o.Name.ToLower().Contains(search)).AsQueryable(); var obj = new MasterDataServiceClient(); var data = new GridModelBuilder<Designation>(items, g) { Key = "DesignationID", // needed for api select, update, tree, nesting, EF GetItem = () => obj.GetAllDesignationsById(UserID, OrganisationID, LangID, Convert.ToInt32(g.Key)), // called by the grid.api.update ( edit popupform success js func ) Map = d => new { d.DesignationID, d.Name, d.Name_OL1, d.Name_OL2 } }.Build(); return Json(data); } but after add edit and delete grid is not auto refereshed and error is coming in jquery at: - itemEdited: function (gridId) { return function (item) { var $grid = $('#' + gridId); var api = $grid.data('api'); var key = $grid.data('o').k; var xhr = api.update(item[key]); $.when(xhr).done(function () { var $row = api.select(item[key])[0]; <<------- Error coming at this place, not getting $row value ------->> var altcl = $row.hasClass("awe-alt") ? "awe-alt" : ""; $row.switchClass(altcl, "awe-changing", 1).switchClass("awe-changing", altcl, 1000); $grid.data('lrso', 1); }); }; }, Please suggest how to work with different key than 'Id'??
Save Changes
Cancel
Prakash Lad
asked at 08 Jun 2016
Answers
B
I
{code}
?
in edit post action have this (same for delete): // returning the key to call grid.api.update return Json(new { Id = dinner.Id }); replace these in utils.js itemDeleted: function (gridId) { return function (res) { var $grid = $("#" + gridId); $grid.data('api').select(res["Id"])[0].fadeOut(500, function () { $(this).remove(); if (!$grid.find('.awe-row').length) $grid.data('api').load(); }); $grid.data('lrso', 1); }; }, itemEdited: function (gridId) { return function (item) { var $grid = $('#' + gridId); var api = $grid.data('api'); var xhr = api.update(item["Id"]); $.when(xhr).done(function () { var $row = api.select(item["Id"])[0]; var altcl = $row.hasClass("awe-alt") ? "awe-alt" : ""; $row.switchClass(altcl, "awe-changing", 1).switchClass("awe-changing", altcl, 1000); $grid.data('lrso', 1); }); }; }, itemCreated: function (gridId) { return function (item) { var $grid = $("#" + gridId); var $row = $grid.data('api').renderRow(item); $grid.find(".awe-content .awe-tbody").prepend($row); $row.addClass("awe-changing").removeClass("awe-changing", 1000); var data = $grid.data('o').lrs.Data; if (data.Items) { data.Items.unshift(item); } else { $grid.data('lrso', 1); } }; },
Save Changes
Cancel
Omu
answered at 08 Jun 2016
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK