Grid not going back to server on row delete

1 Answer 23 Views
Data Source Grid
Eric
Top achievements
Rank 1
Iron
Eric asked on 17 Nov 2023, 08:39 PM

Like the title says, my grid doesn't "call home" on row deletion... read/update/create work just fine (and all go to the same .aspx on the server).

Here's my (edited slightly) code:

var sThisPage = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);

 

$("#divGrid").kendoGrid({ columns: [ { field: 'Department1', title: 'Department', width: 100, editable: telerik_grid_column_onEditable, editor: deptDropDownEditor, template: "${displayDept(Department1)}", }, { field: 'EmployeeID', title: 'Employee', width: 200, editable: telerik_grid_column_onEditable, editor: emplDropDownEditor, template: "${displayEmpl(EmployeeID)}", }, { field: 'SecurityLevel', title: 'Security level', width: 100 }, { field: 'EmplActive', title: 'Active', width: 80, template: "#= EmplActive ? '<span class=\"fa-solid fa-check\"></span>' : '' #" }, ], dataSource: new kendo.data.DataSource({ serverPaging: false, serverFiltering: false, serverSorting: false, //autoSync: true,

requestStart: function (telerikEvent) { }, requestEnd: function (telerikEvent) { }, sync: function (telerikEvent) { var oToolbar = $("#divToolbar").data("kendoToolBar"); var oFirstLine = this._data[0]; if (!oFirstLine.ID || oFirstLine.ID == '') { //First line is a new recordif ((!oFirstLine.Department1 || oFirstLine.Department1 == '') || (!oFirstLine.EmployeeID || oFirstLine.EmployeeID == '') || (!oFirstLine.SecurityLevel || oFirstLine.SecurityLevel == '' || oFirstLine.SecurityLevel == 0)) { alert('New line not saved as some values are missing.'); } } oToolbar.enable("#btnSave", false); oToolbar.enable("#btnCancel", false); }, error: function (e) { if (e.xhr) { alert(e.xhr.responseText); } $("#divGrid").data("kendoGrid").cancelChanges(); }, transport: { read: { url: sThisPage, type: "POST", dataType: "json", cache: false, data: { action: "R" } }, update: { url: sThisPage, type: "POST", dataType: "json", cache: false, data: { action: "U" } }, create: { url: sThisPage, type: "POST", dataType: "json", cache: false, data: { action: "C" } }, destroy: { url: sThisPage, type: "POST", dataType: "json", cache: false, data: { action: "D" } }, }, schema: { model: { id: "ID", fields: { Department1: { type: "number" }, EmployeeID: { type: "number" }, DeptName: { type: "string" }, EmployeeName: { type: "string" }, SecurityLevel: { type: "number", validation: { required: true, min: 1, max: 100 } }, EmplActive: { type: "boolean", editable: false }, } } }, }), editable: true, sortable: true, selectable: "row", change: telerik_grid_onChange, beforeEdit: telerik_grid_onBeforeEdit, edit: telerik_grid_onEdit, cellClose: telerik_grid_onCellClose, remove: function (telerikEvent) { var x = telerikEvent; this.dataSource.sync(); }, });


function telerik_toolbar_button_onClick(telerikEvent) {
	var x = telerikEvent;
	var oGrid = $("#divGrid").data("kendoGrid");
	
	switch (telerikEvent.id) {
/*snip*/
		case 'btnDelete':
			var oSelected = oGrid.select();
			oGrid.removeRow(oSelected);
			break;
	}
}	//telerik_toolbar_button_onClick

If I set breakpoints on the requestStart and requestEnd functions in the data source and delete a line, neither gets hit.

 

Am I doing something wrong?


1 Answer, 1 is accepted

Sort by
0
Eric
Top achievements
Rank 1
Iron
answered on 17 Nov 2023, 09:21 PM

I fixed it!

I swear I tried this before, but I moved the dataSource sync call to after the removeRow call in the button event handler, and it got happy.

Tags
Data Source Grid
Asked by
Eric
Top achievements
Rank 1
Iron
Answers by
Eric
Top achievements
Rank 1
Iron
Share this question
or