$("#Grid").ejGrid({
// the datasource "window.gridData" is referred from jsondata.min.js
dataSource: window.gridData,
allowPaging: true,
actionComplete: function (args) {
if (args.requestType == "beginedit") {
this.element.find(".gridform").find("td").focusout(function () {
debugger;
});
}
},
|
ejUpdateCellOnLostFocus: [ 'productId', 'quantity' ]
ko.bindingHandlers.ejUpdateCellOnLostFocus = { init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { /// <summary>Initializes the Syncfusion Cell Property Update binding handler</summary> /// <param name="element" type="Object">The target Syncfusion Grid</param> /// <param name="valueAccessor" type="Object">The binding configuration in the form of an array of property names.</param> var config = ko.utils.unwrapObservable(valueAccessor()); if (config.constructor !== Array) { return; } // Safely store the configuration and grid identifier within this binding context so the extension can be reused bindingContext.$data.__ejUpdateCellOnLostFocus = config; bindingContext.$data.__ejUpdateCellOnLostFocus_gridId = element.id; $(element).ejGrid({ actionComplete: function(args) { /// <summary>Grid Action Complete handler to adapt Syncfusion Grids to requirements, see: https://goo.gl/Bni3P8 </summary> /// <param name="args" type="Object">The grid event arguments</param> switch (args.requestType) { case ej.Grid.Actions.BeginEdit: { // By using array, you can trigger multiple properties for auto-update $.each(bindingContext.$data.__ejUpdateCellOnLostFocus, function(i, v) { // Attach a focus out handler to each target property wrapper, the DOM elements are removed on end edit, so, no clean-up args.row.find("#" + bindingContext.$data.__ejUpdateCellOnLostFocus_gridId + v + "_wrapper").on("focusout", function () { // Update the row data property with the value from the hidden input for the cell args.rowData[v] = args.row.find("#" + bindingContext.$data.__ejUpdateCellOnLostFocus_gridId + v + "_input").val(); }); }); break; } } } }); } };
ko.bindingHandlers.ejUpdateCellOnLostFocus = { init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { /// <summary>Initializes the Syncfusion Cell Property Update binding handler</summary> /// <param name="element" type="Object">The target Syncfusion Grid</param> /// <param name="valueAccessor" type="Object">The binding configuration in the form of an array of property names.</param> var config = ko.utils.unwrapObservable(valueAccessor()); if (config.constructor !== Array) { return; } $(element).data("__ejUpdateCellOnLostFocus", config); $(element).ejGrid({ actionComplete: function(args) { /// <summary>Grid Action Complete handler to adapt Syncfusion Grids to requirements, see: https://goo.gl/Bni3P8 </summary> /// <param name="args" type="Object">The grid event arguments</param> switch (args.requestType) { case ej.Grid.Actions.BeginEdit: { var gridId = args.target.id, properties = $(args.target).data("__ejUpdateCellOnLostFocus"); $.each(properties, function (i, v) { args.row.find("#" + gridId + v + "_wrapper").on("focusout", function () { var val = args.row.find("#" + gridId + v + "_input").val(); if (args.rowData[v] !== val) { $(args.target).data("__actionCompletedFor", { rowIndex: args.rowIndex, property: v }); args.rowData[v] = val; } }); }); break; } case ej.Grid.Actions.Refresh: { setTimeout(function() { var workaround = $(args.target).data("__actionCompletedFor"); if (workaround) { var grid = $(args.target).data("ejGrid"), columnIndex = grid.getColumnIndexByField(workaround.property) + 1; grid.selectRows(workaround.rowIndex); grid.startEdit(grid.getRowByIndex(workaround.rowIndex)); // TODO: Select the next cell and focus $(args.target).data("__actionCompletedFor", null); } }, 25); break; } } } }); } };