Jump to content

Get current row in a TUniDBGrid using JavaScript


aristeo

Recommended Posts

Hi!

 

In UniDBGrid.ClientEvents.ExtEvents:

 

function OnCellclick(sender, rowIndex, columnIndex, e)
{
  var me = MainForm.UniDBGrid1;
  pos = me.getSelectionModel().getCurrentPosition();
  //alert(pos.column);
 
  ajaxRequest(MainForm.UniDBGrid1,
              'CellChanged',
              ['col='+pos.column,'row='+pos.row]);
}

 

 

function OnKeypress(e)
{
  var me = MainForm.UniDBGrid1;
  pos = me.getSelectionModel().getCurrentPosition();
  //alert(pos.column);
 
  ajaxRequest(MainForm.UniDBGrid1,
              'CellChanged',
              ['col='+pos.column,'row='+pos.row, 'charcode='+e.getCharCode()]);
}

 

 

 

 

Then, in the OnAjaxEvent, an example procedure to get the row and col:

 

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TStrings);
var
  col, row, fld, key, val: string;
  c, r: integer;
begin
  if EventName='CellChanged' then
  begin
    col := Params.Values['col'];
    row := Params.Values['row'];
    key := Params.Values['charcode'];
    UniLabel2.Caption := key;

    if (UpperCase(col)<>'UNDEFINED')and(UpperCase(row)<>'UNDEFINED') then
    begin
        UniLabel1.Text := 'Col: ' + col + ', Row: ' + row;

        c := strtoint(col);
        r := strtoint(row);

        fld := UniDBGrid1.Columns[c].Field.FieldName;

        UniLabel1.Text := UniLabel1.Text + ' - ' + fld +
          ' - ' + ClientDataset1.FieldByName(fld).AsString;
    end;
  end

end;

 

Bye!

 

Bruno

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...