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

add parameter to rowStyles #44

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .changeset/beige-mayflies-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@proofgeist/mantine-tanstack-table": patch
---

added optional rowIndex prop to rowStyles callback. New index is the index after sorting and filtering
5 changes: 5 additions & 0 deletions .changeset/friendly-papayas-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@proofgeist/mantine-tanstack-table": patch
---

row data is now passed into the rowStyles function for row level styling
15 changes: 12 additions & 3 deletions src/tanstack-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
flexRender,
type RowData,
type Table,
Row,
} from "@tanstack/react-table";
import {
Box,
Expand Down Expand Up @@ -100,7 +101,10 @@ type Props<T extends Table<any>> = TableProps & {
columnFilters?: boolean;
// labels?: Partial<typeof defaultLabels>;
perPageOptions?: number[];
rowStyles?: (row: ReturnType<T["getRow"]>) => MantineStyleProp;
rowStyles?: (
row: ReturnType<T["getRow"]>,
rowIndex?: number
) => MantineStyleProp;
stickyTop?: number | null;
stickyFoot?: number | null;
stickyBorderRadius?: string | null;
Expand Down Expand Up @@ -362,7 +366,7 @@ export default function TanstackTable<T extends Table<any>>({
))}
</MTable.Thead>
<MTable.Tbody>
{rows.rows.map((row) => {
{rows.rows.map((row, rowIndex) => {
let shouldBypassPlaceholder = false;
if (
!groupIndividualRows &&
Expand All @@ -380,7 +384,12 @@ export default function TanstackTable<T extends Table<any>>({
onRowClick &&
onRowClick(row as ReturnType<T["getRow"]>);
}}
style={rowStyles as MantineStyleProp}
style={
rowStyles(
row as ReturnType<T["getRow"]>,
rowIndex
) as MantineStyleProp
}
>
{row.getVisibleCells().map((cell) => (
<MTable.Td
Expand Down