-
Notifications
You must be signed in to change notification settings - Fork 15
Control sorting through props for iTwin and iModel tables #223
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
8cc3097
137e2f6
5eb72db
553f764
e279c84
9342a06
7896e66
13484ef
69f0806
72a569d
367c765
bb84e3c
8742b39
98a338f
d4f134e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@itwin/imodel-browser-react", | ||
| "comment": "Controlled table sorting for iTwin/iModel tables", | ||
| "type": "minor" | ||
| } | ||
| ], | ||
| "packageName": "@itwin/imodel-browser-react" | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can unify/simplify the naming a bit. I find the name "model" a bit confusing, although I see it comes from MUI Datagrid (I think?) As it stands, it seems we supply sort in the This seems like a chance to tidy up our naming and make things consistent, if possible.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the name to onOrderbyOptionsChange to match current orderbyOptions prop in iTwinGrid and it also receives the same format (string "column asc/desc")
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rename definitely helps. WDYT about moving to a proper tuple like I might even be tempted to do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya passing string as props is definitely not ideal, its lacking typing/structure. I do think going the array route as you suggested is the way to go. Its also compatible with the dataGrid sorting in MUI |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |
| DataGrid, | ||
| GRID_DEFAULT_LOCALE_TEXT, | ||
| GridColDef, | ||
| GridSortModel, | ||
|
alexdunae marked this conversation as resolved.
Outdated
|
||
| } from "@mui/x-data-grid"; | ||
| import svgMore from "@stratakit/icons/more-vertical.svg"; | ||
| import { Icon } from "@stratakit/mui"; | ||
|
|
@@ -62,6 +63,13 @@ export interface IModelTableMUIProps { | |
| isLoading?: boolean; | ||
| /** Called when more data should be loaded. */ | ||
| fetchMore?: (() => void) | false; | ||
| /** | ||
| * Controlled sort model. When provided, the table's sort state is fully | ||
| * controlled by the parent and must be kept in sync via `onSortModelChange`. | ||
| */ | ||
| sortModel?: GridSortModel; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this just effects the table view, not the tile/card view. My initial thought is that would be good to keep sorting unified between both views. WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i updated the changes to apply to both views as you suggested |
||
| /** Called whenever the sort model changes. */ | ||
| onSortModelChange?: (sortModel: GridSortModel) => void; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -79,6 +87,8 @@ export const IModelTableMUI = ({ | |
| } = {}, | ||
| isLoading, | ||
| fetchMore, | ||
| sortModel, | ||
| onSortModelChange, | ||
| }: IModelTableMUIProps) => { | ||
| // Eagerly load all available data so the table has the full dataset | ||
| // for client-side pagination and sorting. | ||
|
|
@@ -188,6 +198,8 @@ export const IModelTableMUI = ({ | |
| rows={iModels} | ||
| columns={columns} | ||
| loading={isLoading} | ||
| sortModel={sortModel} | ||
| onSortModelChange={onSortModelChange} | ||
| onRowClick={ | ||
| actions | ||
| ? (params) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.