Skip to content

Commit

Permalink
Fix #3215: BodyClassName allow function with rowData (#3439)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Oct 8, 2022
1 parent d1fa32a commit 451c79a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
24 changes: 12 additions & 12 deletions components/doc/datatable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,18 @@ export const DataTableDemo = () => {
<td>null</td>
<td>Body content of the column.</td>
</tr>
<tr>
<td>bodyStyle</td>
<td>object</td>
<td>null</td>
<td>Inline style of the body.</td>
</tr>
<tr>
<td>bodyClassName</td>
<td>string | function</td>
<td>null</td>
<td>Style class of the body. If using a function must return a string.</td>
</tr>
<tr>
<td>footer</td>
<td>any</td>
Expand Down Expand Up @@ -1385,18 +1397,6 @@ export const DataTableDemo = () => {
<td>null</td>
<td>Configuration of the header tooltip, refer to the tooltip documentation for more information.</td>
</tr>
<tr>
<td>bodyStyle</td>
<td>object</td>
<td>null</td>
<td>Inline style of the body.</td>
</tr>
<tr>
<td>bodyClassName</td>
<td>string</td>
<td>null</td>
<td>Style class of the body.</td>
</tr>
<tr>
<td>footerStyle</td>
<td>object</td>
Expand Down
4 changes: 3 additions & 1 deletion components/lib/column/column.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type ColumnHeaderType = React.ReactNode | ((options: ColumnHeaderOptions) => Rea

type ColumnBodyType = React.ReactNode | ((data: any, options: ColumnBodyOptions) => React.ReactNode);

type ColumnBodyClassType = string | ((data: any, options: ColumnBodyOptions) => string);

type ColumnFooterType = React.ReactNode | ((options: ColumnFooterOptions) => React.ReactNode);

type ColumnEditorType = React.ReactNode | ((options: ColumnEditorOptions) => React.ReactNode);
Expand Down Expand Up @@ -184,7 +186,7 @@ export interface ColumnProps {
alignFrozen?: ColumnAlignFrozenType;
alignHeader?: ColumnAlignType;
body?: ColumnBodyType;
bodyClassName?: string;
bodyClassName?: ColumnBodyClassType;
bodyStyle?: object;
cellEditValidatorEvent?: string;
children?: React.ReactNode;
Expand Down
3 changes: 2 additions & 1 deletion components/lib/datatable/BodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ export const BodyCell = React.memo((props) => {
const align = getColumnProp('align');
const value = resolveFieldData();
const cellClassName = ObjectUtils.getPropValue(props.cellClassName, value, { props: props.tableProps, rowData: props.rowData, column: props.column });
const className = classNames(getColumnProp('bodyClassName'), getColumnProp('className'), cellClassName, {
const bodyClassName = ObjectUtils.getPropValue(getColumnProp('bodyClassName'), props.rowData, { column: props.column, field: field, rowIndex: props.rowIndex, frozenRow: props.frozenRow, props: props.tableProps });
const className = classNames(bodyClassName, getColumnProp('className'), cellClassName, {
'p-selection-column': selectionMode !== null,
'p-editable-column': editor,
'p-cell-editing': editor && editingState,
Expand Down
3 changes: 2 additions & 1 deletion components/lib/treetable/TreeTableBodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export const TreeTableBodyCell = (props) => {
}
});

const className = classNames(props.bodyClassName || props.className, {
const bodyClassName = ObjectUtils.getPropValue(props.bodyClassName, props.node.data, { field: props.field, rowIndex: props.rowIndex, props: props });
const className = classNames(bodyClassName || props.className, {
'p-editable-column': props.editor,
'p-cell-editing': props.editor ? editingState : false
});
Expand Down

0 comments on commit 451c79a

Please sign in to comment.