@linzjs/step-ag-grid 21.2.0 → 21.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/Grid.d.ts +2 -1
- package/dist/step-ag-grid.cjs.js +19 -3
- package/dist/step-ag-grid.cjs.js.map +1 -1
- package/dist/step-ag-grid.esm.js +19 -3
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +3 -1
- package/src/contexts/GridContextProvider.tsx +18 -1
- package/src/stories/grid/GridReadOnly.stories.tsx +8 -1
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -39,6 +39,7 @@ export interface GridBaseRow {
|
|
|
39
39
|
|
|
40
40
|
export interface GridProps {
|
|
41
41
|
readOnly?: boolean; // set all editables to false when read only, make all styles black, otherwise style is gray for not editable
|
|
42
|
+
defaultPostSort?: boolean; // Retain sort order after edit, Defaults to true.
|
|
42
43
|
selectable?: boolean;
|
|
43
44
|
theme?: string; // should have prefix ag-theme-
|
|
44
45
|
["data-testid"]?: string;
|
|
@@ -114,6 +115,7 @@ export interface GridProps {
|
|
|
114
115
|
*/
|
|
115
116
|
export const Grid = ({
|
|
116
117
|
"data-testid": dataTestId,
|
|
118
|
+
defaultPostSort = true,
|
|
117
119
|
rowSelection = "multiple",
|
|
118
120
|
suppressColumnVirtualization = true,
|
|
119
121
|
theme = "ag-theme-step-default",
|
|
@@ -742,7 +744,7 @@ export const Grid = ({
|
|
|
742
744
|
onModelUpdated={onModelUpdated}
|
|
743
745
|
onGridReady={onGridReady}
|
|
744
746
|
onSortChanged={ensureSelectedRowIsVisible}
|
|
745
|
-
postSortRows={params.onRowDragEnd ? undefined : postSortRows}
|
|
747
|
+
postSortRows={params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows}
|
|
746
748
|
onSelectionChanged={synchroniseExternalStateToGridSelection}
|
|
747
749
|
onColumnMoved={params.onColumnMoved}
|
|
748
750
|
alwaysShowVerticalScroll={params.alwaysShowVerticalScroll}
|
|
@@ -639,7 +639,24 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
639
639
|
const onFilterChanged = useMemo(
|
|
640
640
|
() =>
|
|
641
641
|
debounce(() => {
|
|
642
|
-
|
|
642
|
+
// This is terrible, but there's no other way for me to check whether a filter has changed the grid
|
|
643
|
+
const getDisplayedRowsHash = () => {
|
|
644
|
+
const arr: any[] = [];
|
|
645
|
+
gridApi?.forEachNodeAfterFilter((rowNode) => {
|
|
646
|
+
arr.push(rowNode.id);
|
|
647
|
+
});
|
|
648
|
+
return arr.join("|");
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
if (gridApi) {
|
|
652
|
+
const hasFocusedCell = gridApi.getFocusedCell();
|
|
653
|
+
const preHash = hasFocusedCell && getDisplayedRowsHash();
|
|
654
|
+
gridApi.onFilterChanged();
|
|
655
|
+
const postHash = hasFocusedCell && getDisplayedRowsHash();
|
|
656
|
+
// Ag-grid has a bug where if a focused cell comes into view after a filter the filter loses focus
|
|
657
|
+
// So the focus is cleared to prevent this
|
|
658
|
+
preHash !== postHash && gridApi.clearFocusedCell();
|
|
659
|
+
}
|
|
643
660
|
}, 200),
|
|
644
661
|
[gridApi],
|
|
645
662
|
);
|
|
@@ -255,7 +255,14 @@ const GridReadOnlyTemplate: StoryFn<typeof Grid> = (props: GridProps) => {
|
|
|
255
255
|
);
|
|
256
256
|
};
|
|
257
257
|
|
|
258
|
-
|
|
258
|
+
type KeysOfType<TObject, TValue> = {
|
|
259
|
+
[K in keyof TObject]: TObject[K] extends TValue ? K : never;
|
|
260
|
+
}[keyof TObject];
|
|
261
|
+
|
|
262
|
+
const GridFilterLessThan = (props: {
|
|
263
|
+
field: KeysOfType<ITestRow, number | null | undefined>;
|
|
264
|
+
text: string;
|
|
265
|
+
}): ReactElement => {
|
|
259
266
|
const [value, setValue] = useState<number>();
|
|
260
267
|
|
|
261
268
|
const filter = useCallback(
|