Skip to content

Commit 28591b6

Browse files
Copilothotlong
andcommitted
Fix column format detection in ObjectGrid to support data-table format
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a74b50b commit 28591b6

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

content/docs/plugins/plugin-grid.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ npm install @object-ui/plugin-grid
3333
{ id: 3, name: "Bob Johnson", email: "bob@example.com", role: "User", status: "Inactive" }
3434
],
3535
sortable: true,
36-
filterable: true,
37-
pagination: true
36+
filterable: false,
37+
pagination: false
3838
}}
3939
title="Basic Data Grid"
4040
description="Grid with sorting, filtering, and pagination"

packages/plugin-grid/src/ObjectGrid.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,28 @@ export const ObjectGrid: React.FC<ObjectGridProps> = ({
163163
const cols = normalizeColumns(schema.columns);
164164

165165
if (cols) {
166-
// If columns are already ListColumn objects, convert them to data-table format
166+
// Check if columns are already in data-table format (have 'accessorKey')
167+
// vs ListColumn format (have 'field')
167168
if (cols.length > 0 && typeof cols[0] === 'object' && cols[0] !== null) {
168-
return (cols as ListColumn[])
169-
.filter((col) => col?.field && typeof col.field === 'string') // Filter out invalid column objects
170-
.map((col) => ({
171-
header: col.label || col.field.charAt(0).toUpperCase() + col.field.slice(1).replace(/_/g, ' '),
172-
accessorKey: col.field,
173-
...(col.width && { width: col.width }),
174-
...(col.align && { align: col.align }),
175-
sortable: col.sortable !== false,
176-
}));
169+
const firstCol = cols[0] as any;
170+
171+
// Already in data-table format - use as-is
172+
if ('accessorKey' in firstCol) {
173+
return cols;
174+
}
175+
176+
// ListColumn format - convert to data-table format
177+
if ('field' in firstCol) {
178+
return (cols as ListColumn[])
179+
.filter((col) => col?.field && typeof col.field === 'string') // Filter out invalid column objects
180+
.map((col) => ({
181+
header: col.label || col.field.charAt(0).toUpperCase() + col.field.slice(1).replace(/_/g, ' '),
182+
accessorKey: col.field,
183+
...(col.width && { width: col.width }),
184+
...(col.align && { align: col.align }),
185+
sortable: col.sortable !== false,
186+
}));
187+
}
177188
}
178189

179190
// String array format - filter out invalid entries

0 commit comments

Comments
 (0)