Beta 3.0.0.0 TWeb(DB)DataGrid.Cells[ACol, ARow] is backward(!)

I discovered that WDG.Cells[i,j] needs to have i = ARow and j = ACol, contrary to Delphi convention.

I await a fix to this bug to resume Beta testing. :face_with_peeking_eye:

This was a tough decision between AgGrid API and classic Delphi.

The code editor clearly indicates how it is accessed:

As we also offer direct AgGrid JS API access via WebDataGrid.AGGrid, we decided to go for the consistency with the AgGrid API.

Ouch! Any chance of reversing that decision? It not only sets a trap for the feckless coder (yours truly) who misses the LSP prompt, but also makes difficult the otherwise relatively simple process of substituting this new component in place of another grid in existing code!

We implemented it consistent with the AGGrid spec from the start of TWebDataGrid. Now we introduce the new component TWebDBDataGrid. We can't change this as it would break existing user applications using TWebDataGrid and doing this different in TWebDataGrid from TWebDBDataGrid would introduce in itself an inconsistency.

Assuming that there are such “existing user apps” of course. :wink:

How about adding a pair of overload classes for these two that follow Pascal conventions for those of us with “existing user apps” that use, e.g., TWebStringGrid and would like to switch to the new components?

Maybe a class helper can assist you?

Maybe. Can that also be in the next update??

You can use this:

type
  TDataGridBaseHelper = class helper for TDataGridBase
  public
    procedure SetCell(ACol, ARow: Integer; const AValue: string);
    function GetCell(ACol, ARow: Integer): string;
  end;

implementation

{ TDataGridBaseHelper }

procedure TDataGridBaseHelper.SetCell(ACol, ARow: Integer; const AValue: string);
begin
  Cells[ARow, ACol] := AValue;
end;

function TDataGridBaseHelper.GetCell(ACol, ARow: Integer): string;
begin
  Result := Cells[ARow, ACol];
end;

Thank you! That looks very promising. I’ll try it out soon.

So far, so good…but I pulled out some hair trying to figure out how I was logging my TWebStringGrid.LoadFromStrings calls before I copped to the realization that TMS had added logging itself in the latest beta Core Source, which I then commented out:

...

for i := 0 to AStrings.Count - 1 do
  begin
    arow.StrictDelimiter := true;
    arow.Delimiter := FDelimiter;
    arow.DelimitedText := AStrings.Strings[i];
    
//    console.log(arow.Delimiter, arow.DelimitedText);
    if arow.Count > maxcol then
      maxcol := arow.Count;
...

Where can I find TWebDBDataGrid documentation/examples for

  1. Setting Row Height?
  2. Setting Column Width and Alignment?
  3. Getting events for OnCellClicked, OnRowSelected, etc. to fire?
  4. Using OnGetRowClass?

The last of these is the only one of them for which my Object Inspector setting is not evidently ignored and it doesn’t seem to work as I expected (i.e., the way it does for TWebDBGrid).

Slipped in this last beta but internally already corrected.

  1. Use grid.RowHeight
  2. Use grid.ColumnDefs[index].Width
  3. Use grid.ColumnDefs[index].OnGetCellStyle with code:
function TForm2.WebDBDataGrid1Column_ModelGetCellStyle(
  Params: TJSCellClassParams): TJSValue;
begin
  Result := JS.New(['textAlign', 'right']);
end;
  1. I retested with TWebDBDataGrid.OnCellClicked & OnRowSelected event handlers assigned and these events are triggered

  2. Example of using OnGetRowClass

function TForm2.WebDBDataGrid1GetRowClass(
  Params: TJSGetRowClassParams): TJSValue;
begin
  if Params.RowIndex = 5 then
  begin
    Result := 'redrow';
  end;
end;

where in CSS, you have defined:

    <style>
      .redrow { background-color: red; }
    </style>

Thanks for these very helpful tips. I’ll try the OnCellClicked and OnRowSelected again, but yesterday they did NOT fire in my app (i.e., I had breakpoints on their events that did not halt execution and their code did not execute).

FYI: I just watched WebDataGrid #3 on YouTube (very nice) but the audio was far too low for comfort.

For some reason my Delphi breakpoints are not working. What switch have I forgotten to set?

The events are firing OK (I was missing some console.log errors yesterday). However, RowHeight works only when specified in code, and ColumnDefs[x].Width does not work for me, whether specified in code or Object Inspector. GetRowClass only works with theming enabled, and fully works only in Chrome (in Edge and FF font color is honored but the background-color spec is ignored). GetCellStyledoes not work in any of the 3 browsers.

BTW, I noticed in today’s YouTube demo that you somehow don’t see the errors from TJSValue that I see (EPG below is a TWebDBDataGrid). How do you accomplish that?

Debug breakpoints: define circumstances, what browser is used, compile in debug mode, ...?
2)
RowHeight is applied to rows that are in the grid
3)
For column width, I cannot see an issue here, please provide a sample source project with which we can reproduce
4)
OnGetRowClass should work regardless of theme. Also here, I can't reproduce, so provide details, sample source project, ... with which it can be reproduced
5)
Add jsDelphiSystem to the uses list

Thanks for the uses update.

On breakpoints: Oops, I didn’t have the project build set to Debug, where it “always” is set! :face_with_spiral_eyes:

I’m still sorting things out (now using Debug builds) and I see that column width settings are honored iff they are set after the DataGrid data are loaded. I.e., LoadFromStringsseems to clear those settings to a set of defaults (and not to the Designer specs). See example project attached below.

In Debug mode, OnGetRowClass does behave properly in my 3 browsers with or without theming enabled. However, in Release mode (where I was inadvertently set before) it depends more quixotically on theming enabling and browser use.

WebDataGridSizingDoodle.zip (12.0 KB)