Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

TWebDBGrid

 Post Reply Post Reply
Author
Gomezel Dino View Drop Down
New Member
New Member
Avatar

Joined: 02 Dec 2010
Posts: 16
Post Options Post Options   Quote Gomezel Dino Quote  Post ReplyReply Direct Link To This Post Topic: TWebDBGrid
    Posted: 28 Aug 2018 at 5:17pm
I need some hints (or a manual) for customizing the output of TWebDBGrid.

I cannot color rows, based on cell content (I have tried with FNC Grid connected to the DB but had same problems), and I dont know how to make the urls behave like hiperlinks.

The APP made in TmsWEB:
https://dino.xcloud.si/owncloud/index.php/s/pKMcn7bXP2RDzh7

And the old one made in Morfik:
(there are tons of developer waiting for TMSWeb - as Morfik has ended development)
https://dino.xcloud.si/owncloud/index.php/s/nE0YyyrYO0cM1Lj

Back to Top
Bruno Fierens View Drop Down
TMS Support
TMS Support
Avatar

Joined: 11 May 2010
Posts: 7895
Post Options Post Options   Quote Bruno Fierens Quote  Post ReplyReply Direct Link To This Post Posted: 29 Aug 2018 at 1:03pm
Create a CSS class 
COLOREDCELL with setting

COLOREDCELL { background-color: red }

in your HTML and implement the event OnGetCellClass:

procedure TForm2.WebDBGrid1GetCellClass(Sender: TObject; ACol, ARow: Integer;
  AField: TField; AValue: string; var AClassName: string);
begin
 if AValue = ... then
   AClassName := 'COLOREDCELL';
end;

Back to Top
Gomezel Dino View Drop Down
New Member
New Member
Avatar

Joined: 02 Dec 2010
Posts: 16
Post Options Post Options   Quote Gomezel Dino Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 2018 at 9:54am
I m doing something wrong, had modified the html by adding the CSS ,
had added the CSS component to the form, even to the main form,
but cannot get the cell colored :-(

<style>
   COLOREDCELL { background-color: red }
</style>
</head>

Any hint? I m headbanging the wall
Back to Top
Bruno Fierens View Drop Down
TMS Support
TMS Support
Avatar

Joined: 11 May 2010
Posts: 7895
Post Options Post Options   Quote Bruno Fierens Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 2018 at 3:25pm
I cannot see a problem. This works right-away here.

Test code with a TWebClientDataSet connected TWebDBGrid:

procedure TForm1.WebDBGrid1GetCellClass(Sender: TObject; ACol, ARow: Integer;
  AField: TField; AValue: string; var AClassName: string);
var
  s:string;
  d,e: integer;
begin
  if acol = 4 then
  begin
    s := inttostr(arow)+'='+avalue;
    val(AValue, d, e);

    if d >= 100 then
    begin
      AClassname := 'COLOREDCELL';
    end;
  end;

end;

procedure TForm1.WebFormCreate(Sender: TObject);
begin
  WebClientConnection1.URI := 'http://www.tmssoftware.biz/tmsweb/fishfacti.json';
  WebClientConnection1.DataNode := 'ROW';
  WebClientDataSet1.FieldDefs.Clear;
  WebClientDataSet1.FieldDefs.Add('_Species_No',ftString,0);
  WebClientDataSet1.FieldDefs.Add('_Category',ftstring,50);
  WebClientDataSet1.FieldDefs.Add('_Common_Name',ftstring,50);
  WebClientDataSet1.FieldDefs.Add('_Species_Name',ftstring,50);
  WebClientDataSet1.FieldDefs.Add('_Length__cm_',ftInteger,0);
  WebClientDataSet1.FieldDefs.Add('_Length_In',ftString,30);
  WebClientConnection1.Active := true;
end;


Test project:
Back to Top
Gomezel Dino View Drop Down
New Member
New Member
Avatar

Joined: 02 Dec 2010
Posts: 16
Post Options Post Options   Quote Gomezel Dino Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 2018 at 5:25pm
OK, Thanks, have found the missing point:

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

In my code was without the point.
   <style>
      COLOREDCELL { background-color: red;}
    </style>
Back to Top
Gomezel Dino View Drop Down
New Member
New Member
Avatar

Joined: 02 Dec 2010
Posts: 16
Post Options Post Options   Quote Gomezel Dino Quote  Post ReplyReply Direct Link To This Post Posted: 30 Aug 2018 at 11:25pm
Now the next question ;-)

I would like to color the entire row based on the value of a cell, if cell is 0 in the 4th column all the row containing that cell should be red (or the color of choice).

And if there is any trick to make the url displayed in some cell to act as hyperlink it would help a lot, as now I have implemented it as a combination of onclick and onmousedown events.
Back to Top
Bruno Fierens View Drop Down
TMS Support
TMS Support
Avatar

Joined: 11 May 2010
Posts: 7895
Post Options Post Options   Quote Bruno Fierens Quote  Post ReplyReply Direct Link To This Post Posted: 31 Aug 2018 at 10:56am
To color the entire row, change your code to:

procedure TForm1.WebDBGrid1GetCellClass(Sender: TObject; ACol, ARow: Integer;
  AField: TField; AValue: string; var AClassName: string);
var
  s:string;
  d,e: integer;
begin
  s := WebClientDataSet1.FieldByName('_Length__cm_').AsString;
  val(s, d, e);

  if d >= 100 then
  begin
     AClassname := 'COLOREDCELL';
  end;
  end;
end;

To make a cell a link:

procedure TForm1.WebDBGrid1GetCellData(Sender: TObject; ACol, ARow: Integer;
  AField: TField; var AValue: string);
begin
  AValue := '<a href="#linkid">'+AValue+'</a>';
end;

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down