EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Wojak on September 10, 2024, 01:02:48 PM



Title: [SOLVED] Datagrid editing row methonds to save and cancel with enter and escape
Post by: Wojak on September 10, 2024, 01:02:48 PM
Hello,
I would like to add to the datagrid the ability to edit after two clicks, I am already able to do this. But also I would like to add that when I start to edit a row then after I click enter or escape it is to save the row or cancel the row. Is there such a possibility?
Also will this only work on one datagrid or many?


Title: Re: Datagrid editing row methonds to save and cancel with enter and escape
Post by: jarry on September 10, 2024, 06:53:44 PM
Please listen to the 'onBeginEdit' event and then bind additional events on each editors.
Code:
$('#dg').datagrid({
onBeginEdit: function (index, row) {
const editors = $(this).datagrid('getEditors', index);
editors.forEach((editor) => {
const t = $(editor.target);
if (t.hasClass('textbox-f')) {
t.textbox('textbox').on('keydown', (e) => {
if (e.which == 13) { // enter
// do your save action
} else if (e.which == 27) { // escape
$('#dg').datagrid('cancelEdit', index)
}
})
}
})
}
})


Title: Re: Datagrid editing row methonds to save and cancel with enter and escape
Post by: Wojak on September 11, 2024, 06:29:15 AM
Works like a charm ;D


Title: Re: [SOLVED] Datagrid editing row methonds to save and cancel with enter and escape
Post by: Wojak on October 25, 2024, 02:35:04 AM
Is there a simple method to save and cancel while being on the page/tab and not in a specific editor?

Also a question, can i add a way in the “onBeginEdit” function that when you click a cell, so that the cursor is already in that editor that is assigned to that cell?