How to customize the column title style in Details list

Viewed 3034

How can I change the font size and padding of the title cell in details list. I am using onRenderDetailsHeader prop to customize header render.

private renderDetailsHeader = (detailsHeaderProps: IDetailsHeaderProps) => {
    return (
      <DetailsHeader
        {...detailsHeaderProps}
        onRenderColumnHeaderTooltip={this.renderCustomHeaderTooltip}
      />
    );
  }

private renderCustomHeaderTooltip = (tooltipHostProps: ITooltipHostProps) => {
  return (
    <span
      style={{
        display: "flex",
        fontFamily: "Tahoma",
        fontSize: "10px",
        justifyContent: "left",
        paddingLeft: '0 px'
      }}
    >
      {tooltipHostProps.children}
   </span>
  );
}

Codepen

3 Answers

In IDetailsHeaderProps['columns'] or simply IColumn[] => IColumn has 'headerClassName' key where you can specify the necessary styles to each of the column.

You can use the IDetailsColumnStyles interface to style the header cells.

Example:

...

  const headerStyle: Partial<IDetailsColumnStyles> = {
    cellTitle: {
      color: theme.palette.orange,
    }
  }

  const columns: IColumn[] = [
    { styles: headerStyle, key: 'name', name: 'Name', fieldName: 'name', minWidth: 100,},

...

Style the Row:

...

const renderRow: IDetailsListProps['onRenderRow'] = props => {
  const rowStyles: Partial<IDetailsRowStyles> = {
    root: {
      borderBottomColor: theme.semanticColors.buttonBorder,
      fontSize: theme.fonts.medium.fontSize,
    },
    cell: { paddingLeft: 0, },
  }
  if (!props) return null
  return <DetailsRow {...props} styles={rowStyles} />
}

return (
  <DetailsList
    compact
    items={items}
    columns={columns}
    selectionMode={SelectionMode.none}
    layoutMode={DetailsListLayoutMode.justified}
    constrainMode={ConstrainMode.horizontalConstrained}
    onRenderRow={renderRow}
    onRenderDetailsHeader={renderHeader}
    onRenderItemColumn={renderItemColumn}
    setKey="set"
    ariaLabelForSelectionColumn="Toggle selection"
    ariaLabelForSelectAllCheckbox="Toggle selection for all items"
    checkButtonAriaLabel="Row Checkbox"
  />
)

...

Related