-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataTable: Allow Enter and Esc to be used in editing to confirm/cancel editing #433
Comments
Currently, since there's no client-side API for doing this, it's a bit hard to make this work: |
CellEditor supports these (editMode="cell"), by design we don't support it for row edit. If more users require it, I'll reopen. |
OK Catagay, but please reconsider. That's the first thing I tried to do as soon as I started typing something in the fields of the edited row. I think it's also a matter of accessibility: right now, you are forced to take the mouse, move its pointer and click on the "check" icon to confirm. I can't think of any good reason for which they shouldn't be implemented "by design". |
Ok, I'll reopen to see if more users will demand it. I have some performance changes upcoming in 5.3 to row editor, maybe will do it along the way. |
I've actually implemented this very functionality (not the escape key) and it was pretty easy to do. However, I added the escape piece because it's pretty simple. I can see why it's not implemented OOTB because it might be difficult to cover all use cases without overstepping boundaries.
|
Actually, I'm currently using the code provided by BalusC on Stackoverflow with no issues so far. It's quite brief. I'm reporting it here how the Enter key is handled: $(document).on("keydown", ".ui-cell-editor-input input", function(event) {
if (event.keyCode == 13) {
$(this).closest("tr").find(".ui-row-editor .ui-icon-check").click();
}
}); |
I'd like this function, or at least the option to enable it for RowEditor. |
We need this option too... All of our customers click ENTER and think something is wrong... |
We need this option too. |
Need this option for "in place" as well :) |
Please create a separate ticket for inplace and we'll discuss. |
I'd like this function as well OOTB. |
+1 |
+1 |
Slightly modified version of the BalusC code cited by @mauromol above:
$(document).on("keydown", ".ui-cell-editor-input input", function(event) {
if (event.keyCode == 13) { // Enter
$(this).closest("tr").find(".ui-row-editor .ui-icon-check").click();
return false; // prevents executing other event handlers (adding new row to the table)
}
if (event.keyCode == 27) { // Escape
$(this).closest("tr").find(".ui-row-editor .ui-icon-close").click();
return false;
}
}); |
@elab. I am using the showcase and your fix for Cell editor is already natively in the latest Showcase Cell Edit event: https://www.primefaces.org/showcase/ui/data/datatable/edit.xhtml This ticket was about ROW editing right? Nevermind: I see you are attaching to the Cell Editor to close the row editor. |
@melloware yes, the ticket is about the row editing.
(just checked that) |
OK I submitted a PR. I modified all answers slightly.
|
@melloware: you made me thinking about, we could in fact catch key events for the row itself (to automatically cover any input elements), this also simplifies the code a bit: $(document).on("keydown", "tr.ui-row-editing", function(event) {
if (event.keyCode == 13) { // Enter
$(this).find(".ui-row-editor .ui-icon-check").click();
return false; // prevents executing other event handlers (adding new row to the table)
}
if (event.keyCode == 27) { // Escape
$(this).find(".ui-row-editor .ui-icon-close").click();
return false;
}
}); |
@elab I think the problem is the |
In the initial state no rows are marked with that, right. |
Cool let me test it locally and update my PR. |
Tested and its working great. PR updated. |
Having a
<p:datatable>
with a<p:rowEditor>
, it would be quite natural to be able to use Enter to confirm editing and Esc to cancel it. Instead, these keys are currently ignored and captured by other elements in the page.The text was updated successfully, but these errors were encountered: