Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MUI DataGrid table pagination not working

I’m trying to make the pagination work in my Material UI DataGrid component but I just cant:

enter image description here

The console doesnt throw any error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is my component:

import { DataGrid } from '@mui/x-data-grid';
import { useSelector } from 'react-redux';

import type { GridRowModel } from '@mui/x-data-grid';
import type { Person } from '../../../../interfaces/people';
import type { AppStore } from '../../../../redux/store';

import { usePeopleTable } from './hooks/usePeopleTable';

const PeopleTable: React.FC = () => {
  const { columns } = usePeopleTable();

  const people: Person[] = useSelector((state: AppStore) => state.people);

  return (
    <>
      <DataGrid
        style={{
          marginTop: '2rem',
          maxWidth: '900px',
          backgroundColor: 'white',
          width: '100%',
        }}
        columns={columns}
        rows={people}
        disableColumnSelector
        disableRowSelectionOnClick
        autoHeight
        pageSizeOptions={[5, 10, 25]}
        paginationMode='client'
        paginationModel={{
          pageSize: 5,
          page: 0,
        }}
        pagination={true}
        getRowId={(row: GridRowModel) => row.id}
      />
    </>
  );
};

export default PeopleTable;

According to the docs this should be fine but it’s driving me crazy, any clue?

Thank youuuu

>Solution :

According to docs, you have to set paginationModel inside pagination.

pagination: { paginationModel: { pageSize: 5 } },

Refer the docs:

import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

export default function PageSizeCustomOptions() {
  const { data } = useDemoData({
    dataSet: 'Commodity',
    rowLength: 100,
    maxColumns: 6,
  });

  return (
    <div style={{ height: 400, width: '100%' }}>
      <DataGrid
        {...data}
        initialState={{
          ...data.initialState,
          pagination: { paginationModel: { pageSize: 5 } },
        }}
        pageSizeOptions={[5, 10, 25]}
      />
    </div>
  );
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading