4

I am using react-redux with hooks, and am trying to display data with ag-grid and infinite scroll work and haven't had any luck. I've made many attempts; here's what I have for now -

import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { fetchItems } from './actions';
import { getItems } from './selectors';

let gridApi = null;
const MyGrid = () => {

  const items = useSelector(getItems);

  const datasource = {
    getRows: ({
      startRow,
      endRow,
      sortModel,
      filterModel,
      successCallback
    }) => {
      const pageSize = endRow - startRow;
      const pageNumber = Math.floor(startRow / pageSize) + 1;
      dispatch(fetchItems({ pageNumber, pageSize }));
      // I think ag-grid expects results to come in successCallback, 
      // but have now way of knowing when they will come in 
    }
  };

   const onGridReady = params => {
     gridApi = params.api;
   };

  return (
    <>
      <div className="ag-theme-balham">
        <AgGridReact
          reactNext={true}
          rowModelType="infinite"
          paginationPageSize={100}
          cacheOverflowSize={2}
          maxConcurrentDatasourceRequests={2}
          maxBlocksInCache={2}
          getRowNodeId={item => item.id}
          datasource={datasource}
          // rowData={items}
          onGridReady={onGridReady}
          defaultColDef={{ sortable: true }}
        >

          <AgGridColumn headerName="Name" field="name" />
          <AgGridColumn headerName="Street" field="street" />
          <AgGridColumn headerName="City" field="city" />
          <AgGridColumn headerName="Phone" field="phoneNumber" />
        </AgGridReact>
      </div>
    </>
  );
};
};
user210757
  • 6,996
  • 17
  • 66
  • 115
  • Did you find a solution? I'm in the same boat. – Vishal Joshi May 16 '20 at 18:32
  • @VishalJoshi I switched to devextreme react grid, it's awesome. However I have moved away from the grid pattern where possible for a more mobile friendly UI. https://devexpress.github.io/devextreme-reactive/react/grid/docs/guides/lazy-loading/ – user210757 Jun 02 '20 at 16:55
  • I have the same problem. Any update from ag-grid? – ourobor93 Jul 09 '20 at 15:57
  • Seems like it's pretty much just not supported - https://github.com/ag-grid/ag-grid/issues/1751#issuecomment-1188947230 – xandermonkey Aug 30 '22 at 15:23

0 Answers0