-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement repeat group rows in horizontal layout
- Loading branch information
1 parent
e68b303
commit 27b9e2c
Showing
13 changed files
with
291 additions
and
12 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
examples/src/pages/tests/horizontal-layout/cell-selection-duplicate-group-rows.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
InfiniteTable, | ||
DataSource, | ||
DataSourcePropCellSelection_MultiCell, | ||
} from '@infinite-table/infinite-react'; | ||
|
||
import type { InfiniteTablePropColumns } from '@infinite-table/infinite-react'; | ||
|
||
import { useState } from 'react'; | ||
|
||
type Developer = { | ||
id: number; | ||
|
||
firstName: string; | ||
lastName: string; | ||
country: string; | ||
city: string; | ||
currency: string; | ||
preferredLanguage: string; | ||
stack: string; | ||
canDesign: 'yes' | 'no'; | ||
hobby: string; | ||
salary: number; | ||
age: number; | ||
}; | ||
|
||
const dataSource = () => { | ||
return fetch(process.env.NEXT_PUBLIC_BASE_URL + '/developers100') | ||
.then((r) => r.json()) | ||
.then((data: Developer[]) => data); | ||
}; | ||
|
||
const columns: InfiniteTablePropColumns<Developer> = { | ||
id: { field: 'id', renderSelectionCheckBox: true }, | ||
|
||
firstName: { | ||
field: 'firstName', | ||
}, | ||
|
||
// preferredLanguage: { field: 'preferredLanguage' }, | ||
// stack: { field: 'stack' }, | ||
}; | ||
|
||
const domProps = { | ||
style: { | ||
height: '80vh', | ||
margin: 10, | ||
}, | ||
}; | ||
|
||
const group_COL = {}; | ||
|
||
export default function GroupByExample() { | ||
const [cellSelection, _setCellSelection] = | ||
useState<DataSourcePropCellSelection_MultiCell>({ | ||
selectedCells: [ | ||
// [2, 'firstName'], | ||
['*', 'firstName'], | ||
// [7, 'preferredLanguage'], | ||
// [3, 'id'], | ||
[3, '*'], | ||
[4, '*'], | ||
[5, '*'], | ||
[11, 'preferredLanguage'], | ||
[15, 'stack'], | ||
], | ||
// deselectedCells: [[3, 'stack']], | ||
defaultSelection: false, | ||
}); | ||
|
||
const [wrapRowsHorizontally, setWrapRowsHorizontally] = useState(true); | ||
const [repeatWrappedGroupRows, setRepeatWrappedGroupRows] = useState(true); | ||
return ( | ||
<> | ||
<button | ||
onClick={() => { | ||
setWrapRowsHorizontally(!wrapRowsHorizontally); | ||
}} | ||
> | ||
toggle horizontal layout | ||
</button> | ||
<button | ||
onClick={() => { | ||
setRepeatWrappedGroupRows(!repeatWrappedGroupRows); | ||
}} | ||
> | ||
toggle repeat wrapped group rows | ||
</button> | ||
<DataSource<Developer> | ||
primaryKey="id" | ||
data={dataSource} | ||
defaultGroupBy={[ | ||
{ | ||
field: 'stack', | ||
}, | ||
{ | ||
field: 'preferredLanguage', | ||
}, | ||
]} | ||
selectionMode="multi-cell" | ||
defaultCellSelection={cellSelection} | ||
> | ||
<InfiniteTable<Developer> | ||
domProps={domProps} | ||
columns={columns} | ||
groupColumn={group_COL} | ||
repeatWrappedGroupRows={repeatWrappedGroupRows} | ||
keyboardSelection={true} | ||
keyboardNavigation={'cell'} | ||
wrapRowsHorizontally={wrapRowsHorizontally} | ||
columnDefaultWidth={200} | ||
/> | ||
</DataSource> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
source/src/components/InfiniteTable/hooks/useHorizontalLayout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useEffect } from 'react'; | ||
import { HorizontalLayoutMatrixBrain } from '../../VirtualBrain/HorizontalLayoutMatrixBrain'; | ||
|
||
import { useInfiniteTable } from './useInfiniteTable'; | ||
|
||
export function useHorizontalLayout() { | ||
const { getState, actions, dataSourceActions, getDataSourceState } = | ||
useInfiniteTable(); | ||
|
||
const { groupBy } = getDataSourceState(); | ||
const { brain, wrapRowsHorizontally, repeatWrappedGroupRows } = getState(); | ||
|
||
useEffect(() => { | ||
if (!wrapRowsHorizontally) { | ||
return; | ||
} | ||
|
||
const onVerticalRenderRangeChange = () => { | ||
const { | ||
rowsPerPage: currentRowsPerPage, | ||
repeatWrappedGroupRows: currentRepeatWrappedGroupRows, | ||
} = getDataSourceState(); | ||
|
||
const rowsPerPage = (brain as HorizontalLayoutMatrixBrain).rowsPerPage; | ||
const newRowsPerPage = groupBy && groupBy.length > 0 ? rowsPerPage : null; | ||
|
||
if (currentRowsPerPage != newRowsPerPage) { | ||
dataSourceActions.rowsPerPage = newRowsPerPage; | ||
} | ||
|
||
if (currentRepeatWrappedGroupRows != !!repeatWrappedGroupRows) { | ||
dataSourceActions.repeatWrappedGroupRows = !!repeatWrappedGroupRows; | ||
} | ||
}; | ||
|
||
onVerticalRenderRangeChange(); | ||
|
||
let timeoutId: any; | ||
const off = brain.onVerticalRenderRangeChange(() => { | ||
onVerticalRenderRangeChange(); | ||
timeoutId = setTimeout(() => { | ||
actions.forceBodyRerenderTimestamp = Date.now(); | ||
}); | ||
}); | ||
|
||
return () => { | ||
clearTimeout(timeoutId); | ||
off(); | ||
}; | ||
}, [brain, wrapRowsHorizontally, groupBy, repeatWrappedGroupRows]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.