Hello
I have a grid and each row can be expanded, using detailInit, to show an inner grid.
I fetch the data beforehand so that I can populate the grid using local data.
In inner grid I have a column with a delete button - using template I call a delete function passing this as a parameter.
// column definition
{
field: "delete",
title: "Delete",
width: 50,
template: "<span class='delete' onclick='delete(this)'><img src='.delete_icon.png'/></span>"
},
my delete function :
function delete(e) { let Loader = KENDO.KendoLoader($("body")); try { Loader.Show(); let row = $(e).closest("tr"); let grid = $(e).closest(".innerGrid"); let dataItem = KENDO.KendoGrid(grid).GetDataItem(row); let innerRowId= dataItem.id; let parentRow = row.parent().closest(".k-detail-row").prev(); let parentDataItem = KENDO.KendoGrid($("#ParentGrid")).GetDataItem(parentRow); KENDO.KendoGrid(grid).DeleteUI([innerRowId]); // DeleteUI gets array of ids to delete , implemented below // if no rows remain in inner grid, I need to update a column's value in the parent row if (KENDO.KendoGrid(grid).HasRows() == false) { grid.hide(); grid.siblings(".noRecordsFound").show(); let updatedDataObj = { id: parentDataItem.id, someColumnOnParentRow: null } KENDO.KendoGrid($("#ParentGrid")).UpdateUI([updatedDataObj]); // UpdateUI gets array of objects to update, implemented below } } catch (error) { debugger; console.log(error.message); } finally { Loader.Hide(); } }
We have created a own KENDO wrapper script for different widgets. Here is the kendoGrid code:
let KENDO = { KendoComponent(jQueryElement, component, options = null) { let kendoComponent = {}; kendoComponent.InitKendoComponent = function () { let kComponent = jQueryElement.data(component); if (!kComponent) { if (options) { kComponent = jQueryElement[component](options).data(component); } else { kComponent = jQueryElement[component]().data(component); } } return kComponent; }; return kendoComponent; }, KendoGrid(jQueryElement, options = null) { let kendoGrid = {}; let kGrid = KENDO.KendoComponent(jQueryElement, "kendoGrid", options).InitKendoComponent(); if (options) kGrid.setOptions(options); kendoGrid.SetOptions = function (options) { kGrid.setOptions(options); return kendoGrid; } kendoGrid.GetData = function () { return Array.from(kGrid.dataSource.data()); } kendoGrid.GetDataItem = function (jQueryTableRow) { return kGrid.dataItem(jQueryTableRow); } kendoGrid.UpdateUI = function (dataToUpdate = []) { dataToUpdate.forEach(obj => { let dataItem = kGrid.dataSource.get(obj.id); if (dataItem) { for (let prop in obj) { if (prop !== "id") { dataItem.set(prop, obj[prop]); } } } }); return kendoGrid; } kendoGrid.DeleteUI = function (idsToDelete = []) { idsToDelete.forEach(id => { let dataItem = kGrid.dataSource.get(id); if (dataItem) kGrid.dataSource.remove(dataItem); }); return kendoGrid; }; kendoGrid.HasRows = function () { return kGrid.dataSource.data().length > 0; } return kendoGrid; } }
It appears that UpdateUI does not function as it should.
When I test I notice that when the last remaining row of inner grid is deleted, the parent row's column is indeed updated to null, the No Records Found message is shown instead of the inner grid, the parent row gets collapsed, and when I expand it the inner grid is shown with the last remaining row.
Suprisingly, if I comment out the UpdateUI line, the inner grid's row gets deleted, without collapsing the inner grid and the No Records Found message is shown as intended (the parent row's column does not get updated in this case, obviously).
Is it a bug in Kendo ? or am I doing something wrong?