function actionComplete(args) {
switch(args.requestType){
case "save":
console.log(resolveReferences(args));
ej.popups.DialogUtility.confirm({
title: 'Add Applications?',
content: "Do you wish to add applications to this user?",
okButton: { text: 'Yes', click: function(){grid.childGrid.startEdit();} },
cancelButton: { text: 'No' },
showCloseIcon: false,
closeOnEscape: true,
animationSettings: { effect: 'Zoom' }
});
break;
}
}
var grid = new ej.grids.Grid({
dataSource:dataManager,
allowGrouping: false,
allowSorting: true,
allowFiltering: true,
allowPaging: true,
allowSelection: true,
pageSettings: {pageCount: 3, pageSizes: true},
filterSettings: {type: 'Menu'},
allowExcelExport: true,
allowPdfExport: true,
locale: 'users',
printMode: 'CurrentPage',
editSettings: {allowAdding: true, allowDeleting: true, allowEditing: true, mode: 'Dialog',showDeleteConfirmDialog: true},
searchSettings: {fields: ['last_name','first_name','middle_name','email']},
contextMenuClick: contextMenuClick,
actionFailure: actionFailure,
actionComplete: actionComplete,
toolbarClick: toolbarClick,
actionBegin: actionBeginEdit,
toolbar: [
@can('create',Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())
'Add',
@endcan
'ExcelExport', 'PdfExport', 'Search'],
columns: [
{ field: 'id', headerText: 'ID', isPrimaryKey: true, visible: false,
validationRules: { required: true, number:true }},
{ field: 'last_name', headerText: 'Last Name', allowGrouping: false,
validationRules: { required: true } },
{ field: 'first_name', headerText: 'First Name', allowGrouping: false,
validationRules: { required: true} },
{ field: 'middle_name', headerText: 'Middle Name', allowGrouping: false,
validationRules: { required: false} },
{ field: 'email', headerText: 'Email', allowGrouping: false,
validationRules: { required: true, email:true } },
{ field: 'password', headerText: 'Password', allowGrouping: false, visible: false},
{ field: 'email_verified_at', headerText: 'Email Verified', allowGrouping: false, allowEditing:false, visible: false},
{ headerText: 'Manage Users',
commands: [
@can('update',Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())
{ type: 'Edit', buttonOption: { iconCss: ' e-icons e-edit', cssClass: 'e-flat' } },
@endcan
@can('delete', Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())
{ type: 'Delete', buttonOption: { iconCss: 'e-icons e-delete', cssClass: 'e-flat' } }
@endcan }]
}
],
contextMenuItems: ['SortAscending', 'SortDescending',
@can('update',Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())'Edit',@endcan
@can('delete', Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())'Delete',@endcan
],
childGrid: applicationsGrid
});
grid.appendTo('#Grid');
var applicationsGrid = {
dataSource: childDataManager,
queryString: 'user_id',
allowSorting: true,
allowPaging: true,
allowSelection: true,
pageSettings: {pageCount: 3, pageSizes: true},
editSettings: {allowAdding: true, allowDeleting: true, allowEditing: true, mode: 'Dialog', showDeleteConfirmDialog: true},
locale: 'applications',
toolbar: [
@can('create',Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())
'Add',
@endcan
],
columns: [
{ field: 'id', headerText: 'ID', isPrimaryKey: true, visible: false,
validationRules: { required: true, number:true },},
{ field: 'user_id', headerText: 'U_ID', visible: false,
validationRules: { required: true, number:true },},
{ field: 'application_id', headerText: 'Application', allowGrouping: false,
validationRules: { required: true },
dataSource: applications, foreignKeyField:'id',foreignKeyValue:'name'},
{ field: 'create', headerText: 'Create Data', allowGrouping: false,
type:'boolean', displayAsCheckBox: true, editType: 'booleanedit' },
{ field: 'read', headerText: 'View Data', allowGrouping: false,
type:'boolean', displayAsCheckBox: true, editType: 'booleanedit' },
{ field: 'update', headerText: 'Edit Data', allowGrouping: false,
type:'boolean', displayAsCheckBox: true, editType: 'booleanedit' },
{ field: 'delete', headerText: 'Delete Access', allowGrouping: false,
type:'boolean', displayAsCheckBox: true, editType: 'booleanedit' },
{ field: 'grant', headerText: 'Grant Access', allowGrouping: false,
type:'boolean', displayAsCheckBox: true, editType: 'booleanedit' },
{ field: 'share', headerText: 'Share', allowGrouping: false,
type:'boolean', displayAsCheckBox: true, editType: 'booleanedit'},
{ headerText: 'Applications',
commands: [
@can('update', Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())
{ type: 'Edit', buttonOption: { iconCss: ' e-icons e-edit', cssClass: 'e-flat' } },
@endcan
@can('delete', Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())
{ type: 'Delete', buttonOption: { iconCss: 'e-icons e-delete', cssClass: 'e-flat' } }
@endcan
]
}
],
contextMenuItems: ['SortAscending', 'SortDescending',
@can('update',Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())'Edit',@endcan
@can('delete', Auth::User()->applications()->where('application_id', Auth::User()->getCurrentApplication())->first())'Delete',@endcan
'PdfExport', 'ExcelExport',
'FirstPage', 'PrevPage', 'LastPage', 'NextPage'],
load: loadChild,
actionComplete: actionCompleteChild,
actionBegin: actionBeginChild,
rowDataBound:rowDataBoundChild,
childGrid: portsGrid
};
Index.js
var grid = new ej.grids.Grid({
dataSource: employeeData,
toolbar: [ 'Add', 'Edit',"Delete","Update","Cancel"],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true,mode:"Dialog" },
columns: [
{ field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right', isPrimaryKey: true, width: 125 },
{ field: 'FirstName', headerText: 'Name', width: 125 },
{ field: 'Title', headerText: 'Title', width: 180 },
{ field: 'City', headerText: 'City', width: 110 }
],
actionComplete: function (args) {
if ((args.requestType === 'save')) {
ej.popups.DialogUtility.confirm({ //confirmation dialog opens
title: 'Add Applications?',
content: "Do you wish to add applications to this user?",
okButton: { text: 'Yes', click: function(){ // execute on yes button click
this.close();
grid = document.getElementById("Grid").ej2_instances[0];
grid.detailRowModule.expand(0);
id = grid.getRowByIndex(0).nextElementSibling.querySelector(".e-control.e-grid .e-lib .e-gridhover").id;
child = document.getElementById(id).ej2_instances[0];
setTimeout(function () {
child.addRecord(); // This will call the addRecord for new data
}, 100);
} },
cancelButton: { text: 'No' },
showCloseIcon: false,
closeOnEscape: true,
animationSettings: { effect: 'Zoom' },
});
},
childGrid: {
…
});
grid.appendTo('#Grid');
|
okButton: { text: 'Yes', click: function(){
this.close();
var grid = document.getElementById("Grid").ej2_instances[0];
var ndx = 0;
if(args.action=='edit'){
ndx = args.rowIndex;
} else if (args.action=='add'){
ndx = args.rows.length-1;
}
grid.detailRowModule.expand(ndx);
var id = grid.getRowByIndex(ndx).nextElementSibling.querySelector(".e-control.e-grid .e-lib .e-gridhover").id;
var child = document.getElementById(id).ej2_instances[0];
setTimeout(function () {
child.addRecord(); // This will call the addRecord for new data
}, 100);
} },