I have created a grid view to view and edit data (see below code). And now I want to do the 2 things:
code:
new ej.grids.Grid({
allowReordering: true,
allowFiltering: false,
allowSorting: false,
allowPaging: true,
allowTextWrap: true,
allowKeyboardNavigation: false,
pageSettings: {pageSize: 10},
selectionSettings: {mode: 'Row'},
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: {
showDeleteConfirmDialog: true,
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: 'Batch'
},
dataSource: new ej.data.DataManager({
headers: [{'X-CSRFToken': getCookie('csrftoken')}],
url: "some_url",
insertUrl: " some_url ",
updateUrl: " some_url ",
removeUrl: " some_url ",
batchUrl: " some_url ",
adaptor: new ej.data.WebMethodAdaptor,
}),
columns: [
{field: 'id', headerText: 'ID', isPrimaryKey: true, isIdentity: true, lockColumn: true, visible: false},
{field: 'item', headerText: 'Item', type: "String"},
{
field: 'description',
headerText: 'Description',
type: "String",
height: 100,
edit: {
create: function(){
elem = document.createElement('textarea');
elem.setAttribute("style", "height: 250px")
return elem;
},
read: function() {
return textarea_obj.value;
},
destroy: function() {
textarea_obj.destroy();
},
write: function(args){
textarea_obj = new ej.inputs.TextBox({
value: args.rowData[args.column.field],
});
textarea_obj.appendTo(elem);
}
}
},
{
field: 'amount',
headerText: 'Amount',
editType: 'numericedit',
format: 'C2',
edit: {params: {decimals: 2}}
},
{
field: 'rate_a',
headerText: 'Insured Rate',
editType: 'numericedit',
format: 'P2',
edit: {params: {decimals: 2}}
},
{field: 'amount_a', headerText: 'Amount A', format: 'C2', allowEditing: false},
{
field: 'rate_b',
headerText: 'Insurer Rate',
editType: 'numericedit',
format: 'P2',
edit: {params: {decimals: 2}}
},
{field: 'amount_b', headerText: 'Amount B', format: 'C2', allowEditing: false},
],
aggregates: [{
columns: [{
type: 'Sum',
field: 'amount',
format: 'C2',
footerTemplate: 'Sum: ${Sum}'
},
{
type: 'Sum',
field: 'amount_a',
format: 'C2',
footerTemplate: 'Sum: ${Sum}'
},
{
type: 'Sum',
field: 'amount_b',
format: 'C2',
footerTemplate: 'Sum: ${Sum}'
}]
}],
actionComplete: function (args) {
if (args.requestType == "save") {
this.refresh();
}
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
let dialog = args.dialog;
dialog.showCloseIcon = false;
dialog.height = 500;
// change the header of the dialog
dialog.header = args.requestType === 'beginEdit' ? 'Edit Record' : 'New Record';
}
}
}, "#gvLine");
|
cellEdit(args) {
(this.grid as any).keyConfigs.enter = ''; // remove the ENTER Key functionality
}
cellSaved(args) {
(this.grid as any).keyConfigs.enter = 'enter'; // restore the ENTER Key functionality
}
|
|
keyPressed(args) {
if (args.key == 'Enter' && this.grid.isEdit) {
args.cancel = true;
}
}
if (args.key == 'Tab' && this.isEdit) {
args.cancel = true;
}
|
Hi Balaji Sekar,
Thank you for you help!
I found the 2nd method did solve my problem and below is the exact code I used, hope this code will help someone else.
keyPressed(args) { {#console.log(this)#} if (args.key == 'Enter' && this.isEdit) { args.cancel = true; } if (args.key == 'Tab' && this.isEdit) { args.cancel = true; } } |