Jump to content

OnEnter method in UnimDBGrid?


likemike

Recommended Posts

  • 2 weeks later...
  • 2 weeks later...
34 minutes ago, likemike said:

Any suggestions?

Sorry for the late response.

On 12/18/2021 at 7:35 PM, likemike said:

The fields in the grid are editable. The user can edit them by directly write into the grid.

Could you please make a simple testcase?

Link to comment
Share on other sites

OK! This is the demo-project "DBGrid Editors" (modified with activated "CellEditor"-property). DBGrid Editors.rar

When I want to display a calculator, when the user edits the salary-column, I need an event fireing when the user doubleclick the salary-field.

And I want to display an extra editor-form when the user edits the name-colum for example. 

In my application one column holds a lot of text and calculations, so I need to open a special editor-form when the user double-click this cell.

Link to comment
Share on other sites

52 minutes ago, likemike said:

When I want to display a calculator, when the user edits the salary-column, I need an event fireing when the user doubleclick the salary-field.

If it's ok for you, you can disable editing, and handle childdoubletap event on the client side.

Link to comment
Share on other sites

Hello!

It's a step in the right direction.

But I need the CellEditor for most of the columns and a "special" editor for a few columns.

If I disable option "dgEditing", I have to open my editor for every column which the user wants to edit - that's not good.

If I enable option "dgEditing", it works nearly perfect, but to make my editor work correctly, I need to disable "dgEditing" before the editor opens. After closing the editor I try to enable "dgEditing" again, but that doesn't work.
Here's my code:
 

procedure TForm.UnimDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
var columnIDX : INTEGER;
begin
    if EventName = '_doubleclick' then 
    begin
        columnIDX:=Params['colidx'].AsInteger;
        
        if columnIDX=2 then 
        begin
            try
                UnimDBGrid1.Options:=UnimDBGrid1.Options-[dgEditing];
                FEditor.ShowModal;
            finally
                UnimDBGrid1.Options:=UnimDBGrid1.Options+[dgEditing]; // that has no effect
            end;
            // here I save the text in my editor memo to the text-field
            QTable.FieldByName('TEXT').AsString:=FEditor.UnimMemo1.Text;
        end;
    end;
end; 

 

Link to comment
Share on other sites

8 hours ago, likemike said:

But I need the CellEditor for most of the columns and a "special" editor for a few columns.

Solution.

1. 

procedure TMainmForm.UnimFormCreate(Sender: TObject);
begin
  // for example for ColumnIndex=5
  UnimDBGrid1.JSInterface.JSAddListener('beforeedit', 'function(me, location){return (location.columnIndex !== 5)}');
  UnimDBGrid1.JSInterface.JSAddListener('childdoubletap', 'function(me, location){if (location.columnIndex == 5) {ajaxRequest(me, "_childdoubletap", ["colIndx="+location.columnIndex])}}')

end;

2.

procedure TMainmForm.UnimDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = '_childdoubletap' then
  begin
    // custom logic
    ShowMessage(Params.Values['colIndx'])
  end;

end;

 

Link to comment
Share on other sites

×
×
  • Create New...