Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

The MUI X Data Grid ignores or rejects getRowId

ErrorgetRowId is set but the grid still cannot find a row id

Short answer

The Data Grid reads each row's id from a property called id by default. If your key has another name, pass getRowId as a function that returns it: getRowId={(row) => row.internalId}. Every id must be unique, and the function should keep the same reference between renders, so define it outside the component.

  • Applies to MUI X Data Grid 7, MUI X Data Grid 8, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at one row object and at the exact prop you passed. getRowId must be a function that receives a row and returns its id.

    console.log(rows[0], rows.length, new Set(rows.map(r => r.internalId)).size)
  2. 2Match what you see, then jump to its fix

    1. 1getRowId="internalId" or getRowId={row.internalId}getRowId is given a field name instead of a functionFix
    2. 2Selection or row updates behave oddly when two rows share an idThe ids are not uniqueFix
    3. 3Sorting and filtering re-run on each render and the grid feels slowgetRowId is recreated on every renderFix

What does the error look like?

  • getRowId is set but the grid still cannot find a row id
  • Selection or updates affect the wrong rows

Cause 1 of 3

getRowId is given a field name instead of a function

1Check

The API reference types getRowId as a function that returns the id of a given row. A string or a value does not match.

grep -rn "getRowId" src/

2Fix

Pass a function that takes the row and returns its identifier.

function getRowId(row) {
  return row.internalId;
}

<DataGrid rows={rows} columns={columns} getRowId={getRowId} />

3Verify

The rows appear and selecting one highlights only that row.

npm run dev

Confirmed by mui.com

Did this fix it?

Cause 2 of 3

The ids are not unique

1Check

The docs state each row must have a unique identifier; the grid uses it for selection and for tracking rows across updates. Compare row count with the count of distinct ids.

console.log(rows.length, new Set(rows.map(getRowId)).size)

2Fix

Return a field that is unique in the data, such as a database primary key. Do not generate ids on the fly, since the docs say that causes issues with other features.

const getRowId = (row) => row.orderNumber; // unique per row

3Verify

The two numbers logged are equal.

console.log(rows.length, new Set(rows.map(getRowId)).size)

Confirmed by mui.com

Did this fix it?

Cause 3 of 3

getRowId is recreated on every render

1Check

The docs say the function should keep the same JavaScript reference between renders. An inline arrow inside the component is a new function each time.

grep -rn "getRowId={(" src/

2Fix

Define the function outside the component, or wrap it in useCallback if it uses component scope.

const getRowId = (row) => row.internalId; // outside the component

// or inside it
const getRowId = React.useCallback((row) => row.internalId, []);

3Verify

Rerender the page with the React DevTools profiler; the grid no longer reprocesses rows each time.

npm run dev

Confirmed by mui.com

Did this fix it?

How do I stop it coming back?

  • Include a stable unique id in the data the API returns, and keep the default id name when you can.
  • Define getRowId at module level.
  • Log row count against distinct id count in development.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.