Jump to content

Catch Return Key with BeforeCellKeyDown


Dimitri

Recommended Posts

12 hours ago, Dimitri said:

How can we catch the Return Key or the Escape Key with the BeforeCellKeyDown event in a FDBGrid ?

Sorry, can you please explain in more detail?

12 hours ago, Dimitri said:

Attached to this message is a simple testcase.

How should we work with the testcase?

Link to comment
Share on other sites

 

I use the BeforeCellKeydown event in ClientEvents.Ext Events :

beforecellkeydown=function beforecellkeydown(sender, td, cellIndex, record, tr, rowIndex, e, eOpts)
{
  var key = e.getKey();
  ajaxRequest(this, "BeforeCellKeyDown", ["keycode="+key], false);
  return true;
}

Then on the UniDBGRid1.OnAjaxEvent :

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
var
  lKey: Integer;
begin
  if EventName = 'BeforeCellKeyDown' then
  begin
    lKey := Params['keycode'].AsInteger;
    UniMemo1.Lines.Add(IntToStr(lKey));
  end;
end;

 

When you are editing a cell, the key pressed is displayed in the memo to the right of the grid. For example, if I press the "A" key, the number 65 is displayed in the memo. If I press the "Tab" key, the number 9 is displayed in the memo. But I can't display the number of the "Return" key in the memo. It also doesn't work with the "Escape" key.

Link to comment
Share on other sites

1 hour ago, Dimitri said:

When you are editing a cell, the key pressed is displayed in the memo to the right of the grid. For example, if I press the "A" key, the number 65 is displayed in the memo. If I press the "Tab" key, the number 9 is displayed in the memo. But I can't display the number of the "Return" key in the memo. It also doesn't work with the "Escape" key.

It works for me. But with one excluding of course:

The following sequence doesn't work
Enter (works) -> ESC (doesn't work) (and this is normal...)

What do you want to achieve?

Link to comment
Share on other sites

It works ! Thanks.

 

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) {
  var grid = sender;

  for (var i = 0; i < columns.length; i++) {
    if (columns[i].getEditor()) {
      columns[i].getEditor().on('specialkey', function(field, e) {
        if (e.getKey() == 13) {
          ajaxRequest(grid, "BeforeCellKeyDown", ["keycode=13"], false);
          return e.keyCode;
        }
      })
    }
  }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...