EasyUI Forum
January 23, 2025, 08:30:12 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] Datagrid editing row methonds to save and cancel with enter and escape  (Read 4929 times)
Wojak
Jr. Member
**
Posts: 63


View Profile WWW Email
« 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?
« Last Edit: September 11, 2024, 06:29:29 AM by Wojak » Logged
jarry
Administrator
Hero Member
*****
Posts: 2283


View Profile Email
« Reply #1 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)
}
})
}
})
}
})
Logged
Wojak
Jr. Member
**
Posts: 63


View Profile WWW Email
« Reply #2 on: September 11, 2024, 06:29:15 AM »

Works like a charm Grin
Logged
Wojak
Jr. Member
**
Posts: 63


View Profile WWW Email
« Reply #3 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?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!