Skip to content

Commit

Permalink
Merge pull request #601 from zilliztech/ui
Browse files Browse the repository at this point in the history
ui-component: support column header formatter
  • Loading branch information
shanghaikid authored Jul 25, 2024
2 parents 3c6ec66 + ddce7b5 commit fb4819f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions client/src/components/grid/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ const EnhancedTableHead: FC<TableHeadType> = props => {
)}

{colDefinitions.map(headCell => {
// get cell style
const cellStyle = headCell.getStyle
? headCell.getStyle(headCell)
: {};

// get header formatter
const headerFormatter =
headCell.headerFormatter || (v => <>{v.label}</>);

return (
<TableCell
key={headCell.id + headCell.label}
Expand All @@ -108,7 +113,7 @@ const EnhancedTableHead: FC<TableHeadType> = props => {
onClick={createSortHandler(headCell.sortBy || headCell.id)}
>
<Typography variant="body1" className={classes.tableHeader}>
{headCell.label}
{headerFormatter(headCell)}
</Typography>

{orderBy === (headCell.sortBy || headCell.id) ? (
Expand All @@ -121,7 +126,7 @@ const EnhancedTableHead: FC<TableHeadType> = props => {
</TableSortLabel>
) : (
<Typography variant="body1" className={classes.tableHeader}>
{headCell.label}
{headerFormatter(headCell)}
</Typography>
)}
</TableCell>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/grid/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type ColDefinitionsType = {
) => void;
getStyle?: (data: any) => {};
formatter?: (data: any, cellData?: any, cellIndex?: number) => any;

headerFormatter?: (def: ColDefinitionsType) => React.ReactNode;
onConnect?: (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
data: any
Expand Down

0 comments on commit fb4819f

Please sign in to comment.