Jump to content

How to call Delphi function in ClientEvent


Masteritec

Recommended Posts

Hi, Please see below code and sample Grid4.

If LastName and FirstName is empty, other columns is not allow edit, but if LastName or FirstName column change position, below code will wrong.

if ((context.field == 3) || (context.field == 4)
      || (context.field == 5) || (context.field == 6)
      || (context.field == 7) || (context.field == 8)) { 
    return ajaxRequest(this, "GridEditing", [], false).responseText == "true";
  };

Quote

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
begin
  if EventName = 'GridEditing' then
  begin
    if (ClientDataSet1.FieldValues['LastName'] = '') and (ClientDataSet1.FieldValues['FirstName'] = '') then
    begin
      UniSession.SendResponse('false');
    end
    else
    begin
      UniSession.SendResponse('true');
    end;
  end;
end;

 

Quote

function beforeedit(editor, context, eOpts)
{
  if ((context.field == 3) || (context.field == 4)
      || (context.field == 5) || (context.field == 6)
      || (context.field == 7) || (context.field == 8)) { 
    return ajaxRequest(this, "GridEditing", [], false).responseText == "true";
  };
}

 

Grid4.zip

Link to comment
Share on other sites

1 hour ago, Masteritec said:

Grid4.zip 145.88 kB · 0 downloads

Can you try to use this approach?

1. 

function beforeedit(editor, context, eOpts)
{
    return ajaxRequest(this, "GridEditing", ["colIdx=" + context.field], false).responseText == "true";
}

2. 

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
var
  ColIdx: Integer;
begin
  if EventName = 'GridEditing' then
  begin
    ColIdx := Params.Values['colIdx'].ToInteger;

    if ((Sender as TUniDBGrid).Columns[ColIdx].FieldName <> 'LastName') and
       ((Sender as TUniDBGrid).Columns[ColIdx].FieldName <> 'FirstName') and
       (ClientDataSet1.FieldValues['LastName'] = '') and
       (ClientDataSet1.FieldValues['FirstName'] = '')
    then
    begin
      UniSession.SendResponse('false');
    end
    else
    begin
      UniSession.SendResponse('true');
    end;
  end;
end;

 

  • Like 1
  • Thanks 1
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...