BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
/// <reference
path="~/GeneratedArtifacts/viewModel.js" /> myapp.ProjectsGridTemplate.Timesheets_render
= function (element, contentItem) { // Write code here. var
itemTemplate = $("<div></div>").attr('id',
'Timesheets') // Append the div element to
screen itemTemplate.appendTo($(element)); contentItem.value.oncollectionchange = function
() { if
(itemTemplate.hasClass('e-grid')) { itemTemplate.ejGrid('destroy'); } var
first = contentItem.children[0], fieldname = []; for
(i = 0; i < first.children.length; i++) { fieldname[i] = { field:
first.children[i].valueModel.name }; } //Rendering the Grid Control itemTemplate.ejGrid( { dataSource:
contentItem.value.data, actionComplete: function
(args) { if
(args.requestType == "save") myapp.applyChanges(); }, editSettings: { allowEditing: true,
allowAdding: true, allowDeleting: true,
editMode: "batch" }, allowPaging: true, toolbarSettings: { showToolbar:
true, toolbarItems:
[ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit,
ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update,
ej.Grid.ToolBarItems.Cancel] }, columns: fieldname } ); } } |
The other issue I have found was 'args.requestType == "save"' had to be changed to "batchsave" in order to save changes I have made to existing rows. However, if I add a new row and enter data, it will save quite happily, but does not actually make it into the database. And next time I run the application, the newly entered rows are gone
columns: [ { field: "TimeID"
}, { field: "Project_Detail_ID"
}, { field: "c_Date",
headerText: "Date", editType:
ej.Grid.EditingType.DatePicker }, { field: "Hours"
}, { field: "Work_Detail",
headerText: "Work Detail"} |
for (i = 0; i < first.children.length; i++) { var fieldName = first.children[i].valueModel.name;
fieldname[i] = { field: fieldName }; if (fieldName == "c_Date") $.extend(fieldname[i], { headerText:"Date", editType:ej.Grid.EditingType.DatePicker, width: 70 }); } |
columns: [ . . . . . { field: "c_Date", headerText: "Date", editType: ej.Grid.EditingType.DatePicker, editParams: { showPopupButton: true } }, |
actionComplete: function(args) { if(args.requestType == "batchsave"){ //Do something } |
myapp.OrdersGridEditingTemplate.Order_render = function (element, contentItem) { // Write code here. var itemTemplate = $("<div></div>").attr('id', 'Order');
//Have a global flag for add window.isAdd = false; // Append the div element to screen itemTemplate.appendTo($(element)); var first = contentItem.children[0], fieldname = []; for (i = 0; i < first.children.length; i++) { fieldname[i] = { field: first.children[i].valueModel.name }; } fieldname[0].isPrimaryKey = true;
//Rendering the Grid Control itemTemplate.ejGrid( { dataSource:contentItem.value.data, editSettings: { allowEditing: true, allowAdding: true, editMode:"batch" }, toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add,"edit", ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, columns: fieldname, beforeBatchAdd: function (args) { window.isAdd = true; }, actionComplete: function (args) { if (args.requestType == "batchsave") {
if (window.isAdd) window.isAdd = false;
myapp.activeDataWorkspace.ApplicationData.saveChanges().then($.proxy(function () { this.refreshContent(); }, this)); myapp.applyChanges(); } }, beforeBatchSave: function (args) {
/*Creating a new entity while adding new records and map the value * Example Shown for one added data only*/ if (window.isAdd) { var data = new myapp.Order(); data.CustomerID = args.batchChanges.added[0]["CustomerID"]; data["EmployeeID"] = args.batchChanges.added[0]["EmployeeID"]; args.batchChanges.added[0] = data; } }, });
contentItem.value.oncollectionchange = function () { var gridObj;
/*Important - Used to prevent the oncollectionchange action on adding new record to vs collection*/ if (window.isAdd) return;
if (itemTemplate.hasClass('e-grid')) { gridObj = itemTemplate.ejGrid('instance'); } var first = contentItem.children[0], fieldname=[]; for (i = 0; i < first.children.length; i++) { fieldname[i] = { field: first.children[i].valueModel.name }; } fieldname[0].isPrimaryKey = true;
if(gridObj) { /*Public method to update columns and dataSource*/ gridObj.columns(fieldname); gridObj.dataSource(contentItem.value.data); } } |