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