award_approval_grid = new ej.grids.Grid({
toolbarClick: award_approval_grid_toolbarClick,
columns: [
{type: 'checkbox', width: 40},
{ field: 'id', headerText: 'ID', isPrimaryKey: true, visible: false,
validationRules: { required: true, number: true },
},
{ field: 'award_date', headerText: 'Date',
},
{ field: 'award_name', headerText: 'Name',
},
]
});
award_approval_grid.appendTo('#award_approval_grid');
How do we in the toolbarClick event, trigger the crudUrl in the dataManager and send all the rows that have the checkbox selected?
Thanks!
<script>
var award_approve_dataManager = new ej.data.DataManager({
url: '/api/Performance/awardApprovals/approve',
crudUrl: '/apip/Performance/awardApprovals/approve/update',
adaptor: new ej.data.UrlAdaptor(),
crossDomain: true,
headers: [{"Authorization": "Bearer {{Auth::User()->api_token}}"}]
});
award_approval_grid = new ej.grids.Grid({
dataSource: award_approve_dataManager,
toolbar: [{text: 'Approve Selected', id: 'award_approval_grid_approve'}],
allowSorting: true,
allowFilter: true,
allowPaging: true,
pageSettings: {pageCount: 3, pageSizes: true},
editSettings: {allowAdding: false, allowDeleting: false, allowEditing: false, mode: 'Normal', showDeleteConfirmDialog: true, },
detailTemplate: '#myAwardsDetailTemplate',
commandClick: my_awards_grid_commandClick,
toolbarClick: award_approval_grid_toolbarClick,
columns: [
{type: 'checkbox', width: 40},
{ field: 'id', headerText: 'ID', isPrimaryKey: true, visible: false,
validationRules: { required: true, number: true },
},
{ field: 'award_date', headerText: 'Date',
},
{ field: 'award_type', headerText: 'Type',
},
{ field: 'award_category', headerText: 'Category',
},
{ field: 'summary', headerText: 'Summary',
},
{ field: 'status', headerText: 'Status',
},
{ field: 'description', headerText: 'Description', visible: false,
},
{
headerText: 'View Form',
commands: [
{type: 'None', title: 'View Form', buttonOption: {iconCss: 'reportsLink', cssClass: 'e-flat'}}
]
},
]
});
award_approval_grid.appendTo('#award_approval_grid');
function award_approval_grid_toolbarClick(args){
switch (args.item.id){
case 'award_approval_grid_approve':
//WHAT GOES HERE TO TRIP A SUBMIT TO THE CRUDURL FOR THE SELECTED ROWS ONLY. THERE ARE NO EDITS ON THE ROW JUST CHECKING THE CHECKBOX
break;
default:
return null;
}
}
</script>
|
award_approval_grid = new ej.grids.Grid({ dataSource: award_approve_dataManager, toolbar: [{text: 'Approve Selected', id: 'award_approval_grid_approve'}], allowSorting: true, allowFilter: true, allowPaging: true, pageSettings: {pageCount: 3, pageSizes: true}, editSettings: {allowAdding: false, allowDeleting: false, allowEditing: true, mode: 'Normal', showDeleteConfirmDialog: true, }, detailTemplate: '#myAwardsDetailTemplate', commandClick: my_awards_grid_commandClick, toolbarClick: award_approval_grid_toolbarClick, columns: [ {type: 'checkbox', width: 40}, { field: 'id', headerText: 'ID', isPrimaryKey: true, visible: false, validationRules: { required: true, number: true }, }, { field: 'award_date', headerText: 'Date', }, { field: 'award_type', headerText: 'Type', allowEditing: false, }, { field: 'award_category', headerText: 'Category', }, { field: 'summary', headerText: 'Summary', }, { field: 'status', headerText: 'Status', }, { field: 'description', headerText: 'Description', visible: false, }, { headerText: 'View Form', commands: [ {type: 'None', title: 'View Form', buttonOption: {iconCss: 'reportsLink', cssClass: 'e-flat'}} ] }, ] }); award_approval_grid.appendTo('#award_approval_grid'); |
var award_approval_grid_toolbarClickNotClicked = true;
function award_approval_grid_toolbarClick(args){
var result = award_approval_grid.getSelectedRecords().map(function(a) {return a.id;});
if(result.length > 0) {
award_approval_grid.query = new ej.data.Query().addParams('updated_ids', result);
if(award_approval_grid_toolbarClickNotClicked){
award_approval_grid.refresh();
award_approval_grid_toolbarClickNotClicked = false;
}
}
}
|
window.customAdaptor = new ej.data.UrlAdaptor();
customAdaptor = ej.base.extend(customAdaptor, {
processResponse: function (data, ds, query, xhr, request, changes) {
request.data = JSON.stringify(data);
return ej.data.UrlAdaptor.prototype.processResponse.call(this, data, ds, query, xhr, request, changes)
},
insert: function (dm, data, tableName) {
return {
url: dm.dataSource.insertUrl || dm.dataSource.crudUrl || dm.dataSource.url,
data: $.param({
__RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value,
//sends the params when insert a record
params: { dataId: 1 },
value: data,
table: tableName,
action: 'insert'
}),
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
}
},
update: function (dm, keyField, value, tableName) {
return {
// type: "POST",
url: dm.dataSource.updateUrl || dm.dataSource.crudUrl || dm.dataSource.url,
data: $.param({
__RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value,
value: value,
table: tableName,
action: 'insert'
}),
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
};
},
remove(dm, keyField, value, tableName) {
return {
type: 'DELETE',
url: dm.dataSource.removeUrl || dm.dataSource.crudUrl || dm.dataSource.url,
data: JSON.stringify({
//sends the params when delete a record
params: { dataId: 1 },
key: value,
keyColumn: keyField,
table: tableName,
action: 'remove'
})
};
}
});
function load(args) {
this.dataSource.adaptor = customAdaptor;
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
}
</script>
|