Skip to content

Unable to apply a style to header fields only #211

@TLINDEN

Description

@TLINDEN

Here's how I setup my column headers:

	// setup column data
	for idx, header := range data.headers {
		columns[idx] = table.NewFlexColumn(strings.ToLower(header),
			header, lengths[idx]).WithFiltered(true).WithStyle(Highlighted)
	}

	filtertbl := FilterTable{
		maxColumns: len(data.headers),
		Rows:       len(data.entries),
		headerIdx:  hidx,
		ctx:        ctx,
		columns:    columns,
	}

	filtertbl.Table = table.New(columns)

The problem is, that the style Highlighted is then applied to all cells of the table, not just the header fields.

I understand the idea to apply a style to a whole column, but sometimes you want to have a somewhat highlighted table header. Is that possible somehow?

I'd expect something like this to style invidual header fields:

	for idx, header := range data.headers {
		columns[idx] = table.NewFlexColumn(
                        table.NewStyledCell(strings.ToLower(header), StyleHeader),
			header, lengths[idx]).WithFiltered(true).WithStyle(NoStyle)
	}

But even if this would work, it would just apply a style to the header field text. What if I want to have the whole cell including the borders to have another background color than the remainder of the table?

best,
Tom

edited to add:

What I CAN do is to add a style to the header string directly, like this:

for idx, header := range data.headers {
    columns[idx] = table.NewFlexColumn(strings.ToLower(header), StyleHeader.Render(header),
    lengths[idx]).WithFiltered(true).WithStyle(NoStyle)
}

But as I said above, this applies to the header text only:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions