Is it possible to use ag-grid infinite scroll with react-redux and hooks?

Viewed 655

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>
    </>
  );
};
};
0 Answers
Related