Is there a way to send back the number of rows affected on an updated with inline batch editing so that I can inform the users how many rows they have successfully updated? I haven't been able to find anything on the web for the Kendo Grid that would help me out. My cshtml file is
@{ ViewData["Title"] = "Index";}@Html.AntiForgeryToken()<h2>Index</h2>@(Html.Kendo().Grid<FacilityDataManager.ViewModels.FDMError> () .Name("grid") .Columns(columns => { columns.Bound(c => c.ID).Hidden(true);//.Hidden(true); columns.Bound(c => c.ScadaDailyID).Hidden(true); columns.Bound(c => c.station_asset_id).Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Station Asset ID").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal;font-weight:700;" }); columns.Bound(c => c.station_id).Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Station ID").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal;" }); columns.Bound(c => c.error_type).Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Error Type").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.reading_date).Format("{0:MM/dd/yyyy}").Filterable(ftb => ftb.Multi(true).CheckAll(true)).Title("Reading Date").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); //change the column below to a checkbox //columns.Bound(c => c.errorCorrected).ClientTemplate("<input type='checkbox' disabled='true' value='#= errorCorrected #' " + " # if (errorCorrected) { #" + "checked='checked'" + "# } #" + "/>" ); columns.Bound(c=> c.operating_hrs).Title("Operating Hours").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.ttl_downtime_hrs).Title("Downtime Hours").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.hrsepwr_hrs).Title("Horsepower Hours").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.fuel_consumed).Title("Fuel Consumed").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.engine_starts_attempts).Title("Engine Start Attempts").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.engine_starts_failed).Title("Engine Start Failures").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.engine_starts_success).Title("Engine Start Successes").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.startup_duration).Title("Startup Duration").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.thruput_mmcf).Title("Throughput MMCF").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.avg_unit_rpm).Title("Average Unit RPM").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.oil_to_comp_cyl).Title("Oil Usage (Compressor)").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.oil_to_pwr_cyl).Title("Oil Usage (Engine)").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.oil_new_cc_hand).Title("Oil Usage (Manual)").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); columns.Bound(c => c.blowdown_cnt).Title("Blowdown Count").HeaderHtmlAttributes(new { style = "overflow: visible; white-space: normal" }); }) .ToolBar(toolbar => { toolbar.Save(); }) .Editable(editable => editable.Mode(GridEditMode.InCell)) .Sortable() .Filterable() .Pageable() .Scrollable(scrollable => scrollable.Height(700)) .Reorderable(reorderable => reorderable.Columns(true)) .Resizable(resizable => resizable.Columns(true)) .ColumnResizeHandleWidth(20) .ColumnMenu() .Navigatable() .DataSource(dataSource => dataSource .Ajax() .Batch(true) .PageSize(20) .ServerOperation(false) .Events(events => events .Error("error_handler") .RequestEnd("refreshGrid") ) //set the fields to non-editable here .Model(model => { model.Id(p => p.ID); model.Field(p => p.ID).Editable(false); model.Field(p => p.station_id).Editable(false); model.Field(p => p.reading_date).Editable(false); model.Field(p => p.error_type).Editable(false); model.Field(p => p.station_asset_id).Editable(false); model.Field(p => p.ScadaDailyID).Editable(false); }) .Read(read => read.Action("Cleanup_Read", "DataCorrection").Data("sendAntiForgery")) .Update(update => update.Action("Cleanup_Update", "DataCorrection").Data("sendAntiForgery")) ))<script type="text/javascript"> function error_handler(e) { if (e.errors) { var message = "Errors:\n"; $.each(e.errors, function (key, value) { if ('errors' in value) { $.each(value.errors, function () { message += this + "\n"; }); } }); alert(message); } } function sendAntiForgery() { return { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() } } function refreshGrid(e) { if (e.type == 'update') { e.sender.read(); } }</script><style> .k-grid { font-size: 9px; width:2000px; } .k-grid td { line-height: 2em; } .k-readonly { color:darkgray; } .k-grid-header { font-weight:700; } .k-grid-header .center-header { text-align: center; } .k-grid-header .wrap-header { height: auto; overflow: visible; white-space: normal; }</style>
And my action controller (using Dapper) is shown below (curiously when I check Affected rows shows -1, so not sure why that happens)
[HttpPost] [ValidateAntiForgeryToken] public IActionResult Cleanup_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<FDMError> errors) { if (errors != null && ModelState.IsValid) { var connectionString = _ConnectionString.Value.ConnectionString; string subject = Regex.Replace(User.Identity.Name, ".*\\\\(.*)", "$1", RegexOptions.None); //subject = "Roberts_C"; int affectedRows = 0; foreach (var correction in errors) { //Run your stored procedure here to do a couple of things //insert into the Scada Daily Table //Update the flag on the ScadaErrors table where the ID = to the ID here int scadaErrorID = correction.ID; string stationAssetID = correction.station_asset_id; string stationID = correction.station_id; string errorType = correction.error_type; DateTime readingDate = correction.reading_date; double operatingHours = correction.operating_hrs; double totalDowntimeHours = correction.ttl_downtime_hrs; int horsepowerHours = correction.hrsepwr_hrs; double fuelConsumed = correction.fuel_consumed; int engineStartAttempts = correction.engine_starts_attempts; int engineStartFailed = correction.engine_starts_failed; int engineStartSuccess = correction.engine_starts_success; double startupDuration = correction.startup_duration; double throughputMMCF = correction.thruput_mmcf; int averageUnitRPM = correction.avg_unit_rpm; double oilUsageCompressor = correction.oil_to_comp_cyl; double oilUsageManual = correction.oil_new_cc_hand; //bool errorCorrected = correction.errorCorrected; int blowdownCount = correction.blowdown_cnt; int scadaDailyID = correction.ScadaDailyID; DynamicParameters p = new DynamicParameters(); p.Add("@ScadaErrorID", correction.ID, dbType: DbType.Int32, direction: ParameterDirection.Input); p.Add("@stationAssetID", correction.station_asset_id, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@stationID", correction.station_id, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@errorType", errorType, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@readingDate", readingDate, dbType: DbType.DateTime, direction: ParameterDirection.Input); p.Add("@operatingHours", operatingHours, dbType: DbType.Double, direction: ParameterDirection.Input); p.Add("@totalDowntimeHours", totalDowntimeHours, dbType: DbType.Double, direction: ParameterDirection.Input); p.Add("@horsepowerHours", horsepowerHours, dbType: DbType.Int32, direction: ParameterDirection.Input); p.Add("@fuelConsumed", fuelConsumed, dbType: DbType.Double, direction: ParameterDirection.Input); p.Add("@engineStartAttempts", engineStartAttempts, dbType: DbType.Int32, direction: ParameterDirection.Input); p.Add("@engineStartFailed", engineStartFailed, dbType: DbType.Int32, direction: ParameterDirection.Input); p.Add("@engineStartSuccess", engineStartSuccess, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@startupDuration", startupDuration, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@throughputMMCF", throughputMMCF, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@averageUnitRPM", averageUnitRPM, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@oilUsageCompressor", oilUsageCompressor, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@oilUsageManual", oilUsageManual, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@blowDownCount", blowdownCount, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@scadaDailyID", scadaDailyID, dbType: DbType.String, direction: ParameterDirection.Input); p.Add("@userID", subject, dbType: DbType.String, direction: ParameterDirection.Input); using (var con = new SqlConnection(connectionString)) { string storedProcName = "scada.usp_UpdateDailyTableByID"; con.Open(); affectedRows += con.Execute(storedProcName, p, commandType: System.Data.CommandType.StoredProcedure); }
} } return Json(errors.ToDataSourceResult(request, ModelState)); } }