-
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.
minor type fixing and release version patch
- Loading branch information
1 parent
743ccdd
commit 4ec13d7
Showing
6 changed files
with
336 additions
and
14 deletions.
There are no files selected for viewing
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
152 changes: 152 additions & 0 deletions
152
www/content/docs/learn/working-with-data/grouped-lazy-load-example.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,152 @@ | ||
import { | ||
InfiniteTable, | ||
DataSource, | ||
DataSourceData, | ||
InfiniteTablePropColumns, | ||
DataSourceProps, | ||
} from '@infinite-table/infinite-react'; | ||
import * as React from 'react'; | ||
import { useMemo } 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 columns: InfiniteTablePropColumns<Developer> = { | ||
country: { field: 'country', header: 'Country' }, | ||
id: { field: 'id', header: 'ID', defaultWidth: 100 }, | ||
salary: { | ||
field: 'salary', | ||
header: 'Salary', | ||
renderValue: ({ value, rowInfo }) => { | ||
if (rowInfo.isGroupRow) { | ||
return ( | ||
<> | ||
Avg: <b>{value}</b> | ||
</> | ||
); | ||
} | ||
return value; | ||
}, | ||
}, | ||
age: { field: 'age', header: 'Age' }, | ||
firstName: { field: 'firstName', header: 'First Name' }, | ||
preferredLanguage: { | ||
field: 'preferredLanguage', | ||
header: 'Preferred Language', | ||
}, | ||
lastName: { field: 'lastName', header: 'Last Name' }, | ||
|
||
city: { field: 'city', header: 'City' }, | ||
currency: { field: 'currency', header: 'Currency' }, | ||
stack: { field: 'stack', header: 'Stack' }, | ||
canDesign: { field: 'canDesign', header: 'Can Design' }, | ||
hobby: { field: 'hobby', header: 'Hobby' }, | ||
}; | ||
|
||
const groupBy: DataSourceProps<Developer>['groupBy'] = [ | ||
{ | ||
field: 'country', | ||
}, | ||
{ | ||
field: 'stack', | ||
}, | ||
]; | ||
|
||
const aggregationReducers: DataSourceProps<Developer>['aggregationReducers'] = { | ||
salary: { | ||
field: 'salary', | ||
reducer: 'avg', | ||
}, | ||
}; | ||
|
||
export default function App() { | ||
const lazyLoad = useMemo(() => ({ batchSize: 40 }), []); | ||
return ( | ||
<DataSource<Developer> | ||
data={dataSource} | ||
primaryKey="id" | ||
groupBy={groupBy} | ||
lazyLoad={lazyLoad} | ||
aggregationReducers={aggregationReducers} | ||
> | ||
<InfiniteTable<Developer> | ||
columns={columns} | ||
columnDefaultWidth={130} | ||
groupColumn={{ | ||
id: 'group-col', | ||
defaultSortable: false, | ||
}} | ||
groupRenderStrategy="single-column" | ||
/> | ||
</DataSource> | ||
); | ||
} | ||
|
||
const dataSource: DataSourceData<Developer> = ({ | ||
pivotBy, | ||
aggregationReducers, | ||
groupBy, | ||
|
||
lazyLoadStartIndex, | ||
lazyLoadBatchSize, | ||
groupRowsState, | ||
groupKeys = [], | ||
sortInfo, | ||
}) => { | ||
if (sortInfo && !Array.isArray(sortInfo)) { | ||
sortInfo = [sortInfo]; | ||
} | ||
const startLimit: string[] = []; | ||
if (lazyLoadBatchSize && lazyLoadBatchSize > 0) { | ||
const start = lazyLoadStartIndex || 0; | ||
startLimit.push(`start=${start}`); | ||
startLimit.push(`limit=${lazyLoadBatchSize}`); | ||
} | ||
const args = [ | ||
...startLimit, | ||
pivotBy | ||
? 'pivotBy=' + JSON.stringify(pivotBy.map((p) => ({ field: p.field }))) | ||
: null, | ||
`groupKeys=${JSON.stringify(groupKeys)}`, | ||
`prefetchGroupKeys=${JSON.stringify(groupRowsState?.expandedRows || [])}`, | ||
groupBy | ||
? 'groupBy=' + JSON.stringify(groupBy.map((p) => ({ field: p.field }))) | ||
: null, | ||
sortInfo | ||
? 'sortInfo=' + | ||
JSON.stringify( | ||
sortInfo.map((s) => ({ | ||
field: s.field, | ||
dir: s.dir, | ||
})), | ||
) | ||
: null, | ||
aggregationReducers | ||
? 'reducers=' + | ||
JSON.stringify( | ||
Object.keys(aggregationReducers).map((key) => ({ | ||
field: aggregationReducers[key].field, | ||
id: key, | ||
name: aggregationReducers[key].reducer, | ||
})), | ||
) | ||
: null, | ||
] | ||
.filter(Boolean) | ||
.join('&'); | ||
return fetch( | ||
process.env.NEXT_PUBLIC_BASE_URL + `/developers10k-sql?` + args, | ||
).then((r) => r.json()); | ||
}; |
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
113 changes: 113 additions & 0 deletions
113
www/content/docs/reference/scrollStopDelay-lazy-load-example.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,113 @@ | ||
import { | ||
InfiniteTable, | ||
DataSource, | ||
DataSourceData, | ||
InfiniteTablePropColumns, | ||
} from '@infinite-table/infinite-react'; | ||
import * as React from 'react'; | ||
import { useMemo } 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 columns: InfiniteTablePropColumns<Developer> = { | ||
id: { field: 'id', header: 'ID', defaultWidth: 100 }, | ||
salary: { field: 'salary', header: 'Salary' }, | ||
age: { field: 'age', header: 'Age' }, | ||
firstName: { field: 'firstName', header: 'First Name' }, | ||
preferredLanguage: { | ||
field: 'preferredLanguage', | ||
header: 'Preferred Language', | ||
}, | ||
lastName: { field: 'lastName', header: 'Last Name' }, | ||
country: { field: 'country', header: 'Country' }, | ||
city: { field: 'city', header: 'City' }, | ||
currency: { field: 'currency', header: 'Currency' }, | ||
stack: { field: 'stack', header: 'Stack' }, | ||
canDesign: { field: 'canDesign', header: 'Can Design' }, | ||
hobby: { field: 'hobby', header: 'Hobby' }, | ||
}; | ||
|
||
export default function App() { | ||
const lazyLoad = useMemo(() => ({ batchSize: 40 }), []); | ||
return ( | ||
<DataSource<Developer> | ||
data={dataSource} | ||
primaryKey="id" | ||
lazyLoad={lazyLoad} | ||
> | ||
<InfiniteTable<Developer> | ||
columns={columns} | ||
columnDefaultWidth={130} | ||
scrollStopDelay={50} | ||
/> | ||
</DataSource> | ||
); | ||
} | ||
|
||
const dataSource: DataSourceData<Developer> = ({ | ||
pivotBy, | ||
aggregationReducers, | ||
groupBy, | ||
|
||
lazyLoadStartIndex, | ||
lazyLoadBatchSize, | ||
groupKeys = [], | ||
sortInfo, | ||
}) => { | ||
if (sortInfo && !Array.isArray(sortInfo)) { | ||
sortInfo = [sortInfo]; | ||
} | ||
const startLimit: string[] = []; | ||
if (lazyLoadBatchSize && lazyLoadBatchSize > 0) { | ||
const start = lazyLoadStartIndex || 0; | ||
startLimit.push(`start=${start}`); | ||
startLimit.push(`limit=${lazyLoadBatchSize}`); | ||
} | ||
const args = [ | ||
...startLimit, | ||
pivotBy | ||
? 'pivotBy=' + JSON.stringify(pivotBy.map((p) => ({ field: p.field }))) | ||
: null, | ||
`groupKeys=${JSON.stringify(groupKeys)}`, | ||
groupBy | ||
? 'groupBy=' + JSON.stringify(groupBy.map((p) => ({ field: p.field }))) | ||
: null, | ||
sortInfo | ||
? 'sortInfo=' + | ||
JSON.stringify( | ||
sortInfo.map((s) => ({ | ||
field: s.field, | ||
dir: s.dir, | ||
})), | ||
) | ||
: null, | ||
aggregationReducers | ||
? 'reducers=' + | ||
JSON.stringify( | ||
Object.keys(aggregationReducers).map((key) => ({ | ||
field: aggregationReducers[key].field, | ||
id: key, | ||
name: aggregationReducers[key].reducer, | ||
})), | ||
) | ||
: null, | ||
] | ||
.filter(Boolean) | ||
.join('&'); | ||
return fetch( | ||
process.env.NEXT_PUBLIC_BASE_URL + `/developers10k-sql?` + args, | ||
).then((r) => r.json()); | ||
}; |