I have the following working method for color-coding a data table. However, it seems to cause a lot of overhead such that tables with more than a hundred, or so, cells take way too long to update. In a VCL app I think I could use DBG.DisableControls/EnableControls
to mitigate this slowdown, but those methods appear not to be included for TWebDBGrid
. What should I do instead?
procedure TCWRmainFrm.WebDBGrid1GetCellClass(Sender: TObject; ACol,
ARow: Integer; AField: TField; AValue: string; var AClassName: string);
{ show listings in color code for type based on current IDB record }
var
AColor: string;
Text: string;
begin
if ARow = 0 then exit;
// Prevent recursion
WebDBGrid1.OnGetCellClass := nil;
AClassName := 'redfont';
AColor := '';
if WIDBCDS.Locate('id', WebDBGrid1.Cells[3,ARow],[]) then
begin
Text := WIDBCDS.Fields[8].AsString; // i.e. ProgramID
// if not Text.Contains('EP') then console.log(Text);
if Text.Contains('MV') then // Movie item
AColor := 'goldenRod'
else if Text.Contains('SH') then // Generic item
AColor := 'gray'
else begin
if WIDBCDS.Fields[10].AsString <> '' then // New item
AColor := 'green'
else // Rerun item
AColor := 'rose';
end;
if AColor > '' then AClassName := AColor;
end;
// Restore link
WebDBGrid1.OnGetCellClass := WebDBGrid1GetCellClass;
end;