本帖最后由 Richard.Ma 于 2021-8-26 10:10 编辑
您好,切换数据源然后滚动后未刷新的原因已经确认,是由于virtualOrderDetails.setWindow实际上设置的是老的数据源,而无法对切换后的数据源生效
因此需要将
virtualOrderDetails.setWindow(rng.row,rng.row2); 改为 flexGrid.itemsSource.setWindow(rng.row,rng.row2);
可以参考下面修改后的代码,
https://stackblitz.com/edit/react-e1weyb?file=src/Grid.jsx
- import * as wjcCore from '@grapecity/wijmo';
- import * as wjcGrid from '@grapecity/wijmo.grid';
- import * as wjcOData from '@grapecity/wijmo.odata';
- import * as wjGrid from '@grapecity/wijmo.react.grid';
- import * as React from 'react';
- import { useParams } from 'react-router-dom';
- const fieldMap = {
- 100: 'Customers',
- 2000: 'Order_Details_Extendeds'
- };
- const Grid = () => {
- const [totalItemCount, setTotalItemCount] = React.useState('');
- const [data, setData] = React.useState(null);
- const [flexGrid, setFlexGrid] = React.useState(null);
- const onFlexGridInitialized = React.useCallback(async flexGrid => {
- setFlexGrid(flexGrid);
- flexGrid.scrollPositionChanged.addHandler(() => {
- let rng = flexGrid.viewRange;
- flexGrid.itemsSource.setWindow(rng.row, rng.row2);
- });
- });
- const { count } = useParams();
- const getData = React.useCallback(() => {
- const virtualOrderDetails = new wjcOData.ODataVirtualCollectionView(
- 'https://services.odata.org/Northwind/Northwind.svc',
- fieldMap[count],
- {
- // oDataVersion: 4.0,
- sortOnServer: true,
- filterOnServer: true,
- loaded: (sender, e) => {
- const totalItemCount = wjcCore.format(
- '{totalItemCount:n0} items',
- sender
- );
- setTotalItemCount(totalItemCount);
- }
- }
- );
- setData(virtualOrderDetails);
- }, [count]);
- React.useEffect(() => {
- setData(null);
- void getData();
- }, [getData]);
- return (
- <div className="container-fluid">
- <div className="col-sm-6">
- <h4>ODataVirtualCollectionView</h4>
- <p>{totalItemCount}</p>
- <wjGrid.FlexGrid
- itemsSource={data}
- isReadOnly={true}
- initialized={onFlexGridInitialized}
- />
- </div>
- </div>
- );
- };
- export default Grid;
复制代码
|