Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3310: RowExpansionTemplate allow for custom rendering #3317

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/doc/datatable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3301,7 +3301,7 @@ export const DataTableStateDemo = () => {
<td>rowExpansionTemplate</td>
<td>function</td>
<td>null</td>
<td>Function that receives the row data as the parameter and returns the expanded row content.</td>
<td>Function that receives the row data as the parameter and returns the expanded row content. You can override the rendering of the content by setting options.customRendering = true.</td>
</tr>
<tr>
<td>expandedRows</td>
Expand Down
14 changes: 11 additions & 3 deletions components/lib/datatable/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,14 +903,22 @@ export const TableBody = React.memo(

const createExpansion = (rowData, index, expanded, colSpan) => {
if (expanded && !(isSubheaderGrouping && props.expandableRowGroups)) {
const content = ObjectUtils.getJSXElement(props.rowExpansionTemplate, rowData, { index });
const id = `${props.tableSelector}_content_${index}_expanded`;
const options = { index, customRendering: false };
let content = ObjectUtils.getJSXElement(props.rowExpansionTemplate, rowData, options);

return (
<tr id={id} className="p-datatable-row-expansion" role="row">
// check if the user wants complete control of the rendering
if (!options.customRendering) {
content = (
<td role="cell" colSpan={colSpan}>
{content}
</td>
);
}

return (
<tr id={id} className="p-datatable-row-expansion" role="row">
{content}
</tr>
);
}
Expand Down
1 change: 1 addition & 0 deletions components/lib/datatable/datatable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ interface DataTableRowReorderParams {

interface DataTableRowExpansionTemplate {
index: number;
customRendering: boolean;
}

interface DataTableRowClassNameOptions {
Expand Down