Jump to content

How To Change The Background And Font Colour Of the GroupHeader Property For TUniDBGrid's Column?


Frederick

Recommended Posts

I am currently using the following code to change the column title colours:-

    grdGrid.Columns[0].Title.Color:=clYellow;
    grdGrid.Columns[0].Title.Font.Color:=clBlack;
    for nI := 1 to grdGrid.Columns.Count-1 do begin
        grdGrid.Columns[nI].Title.Color:=clGreen;
        grdGrid.Columns[nI].Title.Font.Color:=clWhite;
    end;

How do I access the last 2 column's GroupHeader?

Link to comment
Share on other sites

One possible solution:

function afterlayout(sender, layout, eOpts)
{
    function getAllHeaders(column, headers) {
        if (column.ownerCt && column.ownerCt.isColumn) {
            headers.push(column.ownerCt);
            getAllHeaders(column.ownerCt, headers);
        }
    }

    sender.getColumnManager().getColumns().forEach(function(col) {
        var headers = [];
        if (col.isSubHeader) {
            getAllHeaders(col, headers);
            //col.hoverCls = 'customHover';
            headers.forEach(function(header) {
                if (header.titleEl.getStyle('background-color') == 'transparent') { 
                    header.titleEl.setStyle('background-color', col.titleEl.getStyle('background-color'));
                    header.titleEl.setStyle('color', col.titleEl.getStyle('color'));
                    //header.hoverCls = 'customHover';
                }
            })
        }
    })
}

 

Link to comment
Share on other sites

  • 2 months later...

This is a follow-up to the solution above.

If you see the screenshot attached, when the grid does not have data, the group title's background and font colour does not change.

However, once data is present in the grid, the JS code above works.

How do I fix this?

Note: This is with UniGUI 1.95.0.1577.

gridgroupbackcolour.png

Link to comment
Share on other sites

On 12/29/2023 at 5:06 PM, Frederick said:

If you see the screenshot attached, when the grid does not have data, the group title's background and font colour does not change.

Hello,

One possible solution:

procedure TMainForm.UniFormReady(Sender: TObject);
begin
  with UniDBGrid1 do
    if (not Assigned(DataSource)) or (DataSource.DataSet.IsEmpty) then
      JSInterface.JSCall('getStore().load', [])
end;

 

Link to comment
Share on other sites

I have added the above condition as follows:-

   with UniDBGrid1 do begin
      if (not Assigned(DataSource)) or (DataSource.DataSet.IsEmpty) or (not DataSource.DataSet.Active) then
         JSInterface.JSCall('getStore().load', []);
   end;

and condition 2 is triggered but the JS call is not doing anything.

Link to comment
Share on other sites

Here is the testcase. Interestingly, regardless of whether it is a clientdataset or SQLite as the datasource for the grid, the group title's background does not change.

Note: I use PostgreSQL as the database and the group header shows correctly when there is data but not when there is none.

gridhdr2.7z

Link to comment
Share on other sites

1 hour ago, Frederick said:

gridhdr2.7z 2.18 MB · 0 downloads

Please be attentive!

You are making a mistake in the afterlayout function, I have corrected.

function afterlayout(sender, layout, eOpts)
{
//  function afterlayout(sender, layout, eOpts)
//{
    function getAllHeaders(column, headers) {
        if (column.ownerCt && column.ownerCt.isColumn) {
            headers.push(column.ownerCt);
            getAllHeaders(column.ownerCt, headers);
        }
    }

    sender.getColumnManager().getColumns().forEach(function(col) {
        var headers = [];
        if (col.isSubHeader) {
            getAllHeaders(col, headers);
            //col.hoverCls = 'customHover';
            headers.forEach(function(header) {
                if (header.titleEl.getStyle('background-color') == 'transparent') { 
                    header.titleEl.setStyle('background-color', col.titleEl.getStyle('background-color'));
                    header.titleEl.setStyle('color', col.titleEl.getStyle('color'));
                    //header.hoverCls = 'customHover';
                }
            })
        }
    })
//}

}

 

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