- Home
- Forum
- JavaScript - EJ 2
- EJ2 Javascript Grid: How to customize delete confirmation dialog message
EJ2 Javascript Grid: How to customize delete confirmation dialog message
Hello,
On my grid, I have activated showDeleteConfirmDialog to true. How to customize the delete confirmation dialog message? and adding some of selected record data.
note:
I have found a detail instruction for EJ1 for this case, but did not found any for EJ2 Javascript.
|
ej.base.L10n.load({
'en-US': {
grid: {
ConfirmDelete: 'Click Ok to delete the record'
}
}
});
|
Hi Rajapandiyan,
Thank you for your support. I have try your suggestion and its work:
But the problem is, I want show selected row data to be showed at delete confirmation content, how do I do that?. Like the one describe at EJ1: https://www.syncfusion.com/kb/5059/how-to-customize-the-delete-confirmation-dialog
Best,
Ismail
|
[index.js]
var grid = new ej.grids.Grid({
dataSource: window.orderData,
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
showDeleteConfirmDialog: true
},
allowPaging: true,
pageSettings: { pageCount: 5 },
toolbar: ['Add', 'Edit', 'Delete', 'Cancel', 'Update'],
toolbarClick: toolbarClick,
columns: [
----
]
});
grid.appendTo('#Grid');
function toolbarClick(args) {
if ( args.item.text == 'Delete' && args.item.id == this.element.id + '_delete') { // perform the below action when click the Delete button
// get the selected Records
var selectedRecords = this.getSelectedRecords();
if (selectedRecords.length > 0) {
var value = '';
// get the columns in Grid
var columns = this.getColumns();
// get the cell values from the selected record
for (var i = 0; i < columns.length; i++) {
value = value + columns[i].field + ' - ' + selectedRecords[0][columns[i].field] + '</br>' + '</br>';
}
// customize the confirmDelete message based on the selected record
this.defaultLocale.ConfirmDelete = '<b>Click OK to Delete Record of </b>' + '</br></br>' + value;
}
}
}
|
Please get back to us if you need further assistance with this.
Hi Rajapandiyan,
Thank you for your support, your suggestion work perfectly!
Best regards,
Ismail
Hi Rajapandiyan,
After full testing, it seems handling the toolbarClick make the default behaviour not working. In other words, it did not delete the data.
note:
I'm using RemoteSaveAdaptor for actual CRUD process:
var dataSource = new ej.data.DataManager({
json: [],
adaptor: new ej.data.RemoteSaveAdaptor(),
insertUrl: '/api/Todo/Insert',
updateUrl: '/api/Todo/Update',
removeUrl: '/api/Todo/Delete',
});
Does it means I should override the delete process at toolbarClick? by calling the delete API manually? Or I can "kind of" call some method at toolbarClick so the Delete process still handled by DataManager RemoteSaveAdaptor. Please advice.
toolbarClick: (args) => {
if (args.item.id === grid.element.id + '_excelexport') {
grid.showSpinner();
grid.excelExport();
}
if (args.item.id === grid.element.id + '_delete') {
var selectedRecords = grid.getSelectedRecords();
if (selectedRecords.length > 0) {
var value = '';
var columns = grid.getColumns();
for (var i = 0; i < columns.length; i++) {
value = value + columns[i].field + ' - ' + selectedRecords[0][columns[i].field] + '</br>' + '</br>';
}
grid.defaultLocale.ConfirmDelete = '<b>Are you sure want to delete? </b>' + '</br></br>' + value;
}
}
},
Best regards,
Ismail
|
[index.js]
function toolbarClick(args) {
if (args.item.text == 'Delete' && args.item.id == this.element.id + '_delete') {
var selectedRecords = this.getSelectedRecords();
if (selectedRecords.length > 0) {
var value = '';
var columns = this.getColumns();
for (var i = 0; i < columns.length; i++) {
value = value + columns[i].field + ' - ' + selectedRecords[0][columns[i].field] + ' ';
}
// bind string values only for locale keywords (don’t use htmlstring element)
this.defaultLocale.ConfirmDelete = 'Click OK to Delete Record of :(' + value + ')';
}
}
}
|
Please get back to us if you need further assistance with this.
Hi Rajapandiyan,
Its work after removing HTML string as per your suggestions.
Thank you for your kind support.
Best regards,
Ismail.
Please get back to us if you need further assistance.
- 8 Replies
- 2 Participants
- Marked answer
-
IH ISMAIL HAMZAH
- Jul 26, 2021 04:00 AM UTC
- Aug 2, 2021 03:41 AM UTC