Code Monkey home page Code Monkey logo

Comments (8)

conerye avatar conerye commented on August 26, 2024 1

We tried to create a demo... The issue doesn't show in codesandbox though, probably for the same reason it doesn't show in our development environment; it only shows with a production build/on our test machines. But here is the codesandbox that was created from altering the MUI demo code sandbox for the detail panel:
https://codesandbox.io/p/sandbox/competent-breeze-w4pr2z?file=%2Fsrc%2FDemo.js%3A73%2C12

It is a simple example to show what we are trying to do... in our scenario, if there is none of a particular type of item in the list, then we do not want to show the column for the expansion panel - shown in the demo as a check for a particular name:
getDetailPanelContent={hasName ? getDetailPanelContent : null}
so the value for the getDetailPanelContent prop is null if there are none of a particular item in the list...

Is there is different/recommended way to do this?

from mui-x.

cherniavskii avatar cherniavskii commented on August 26, 2024

Hi @conerye
This looks like a race condition.
Can you try upgrading the Data Grid to the latest v6 release? Can you still reproduce the issue?

from mui-x.

cherniavskii avatar cherniavskii commented on August 26, 2024

Also, could you create a demo that would mimic your Data Grid setup? Thanks!

from mui-x.

conerye avatar conerye commented on August 26, 2024

I upgraded to version 6.19.9 and tried this scenario on our test environment again... Now every time I refresh there's no option for a detail panel expansion and clicking the row gives an app error. I was seeing this occasionally before but it's on every refresh post upgrade.

from mui-x.

michelengelen avatar michelengelen commented on August 26, 2024

The way you pass in the getter function is slightly incorrect.
The function has to be called on every row, so you would be returning your detail panel.

Try refactoring to include the check and return null if the check fails:

const getDetailPanelContent = React.useCallback(
  ({ row }) => {
    if (row.customer === "Matheus") return null
    return <DetailPanelContent row={row} />
  },
  [],
);

... in the data grid props:

<DataGridPro
  columns={columns}
  rows={rows}
  getDetailPanelHeight={getDetailPanelHeight}
  getDetailPanelContent={getDetailPanelContent}
/>

That way you can ensure that the function is always callable and returns the desired result.
Like this the button is also disabled when no content is available.

Does that work for you?

from mui-x.

cherniavskii avatar cherniavskii commented on August 26, 2024

@conerye

here is the codesandbox that was created from altering the MUI demo code sandbox for the detail panel:
codesandbox.io/p/sandbox/competent-breeze-w4pr2z?file=%2Fsrc%2FDemo.js%3A73%2C12

I downloaded the sandbox and ran it locally in production mode (npm run build && npx server -s build) – I can't reproduce the issue.
Is the setup close to what you do? Do you also render a data grid inside the detail panel?

from mui-x.

conerye avatar conerye commented on August 26, 2024

Changing our code, as michelengelen suggested, so that getDetailPanelContent always has a callable function and then refactoring the function to include the check and return null if the check fails, does work and we are not able to reproduce the Unexpected Application error with the code this way. The difference is that now the detail panel expansion column shows even when there are no rows in the table that meet the criteria for the detail panel expansion -> all rows have the expansion icon disabled. So, the Unexpected Application problem is resolved, BUT we would like to know if there is a way to hide the detail panel expansion column in this scenario (no rows will ever have the detail panel)?

from mui-x.

michelengelen avatar michelengelen commented on August 26, 2024

@conerye ... you would need to have an additional check for that:
Basically the same as before, but when the condition is falsey the value for getDetailPanelContent needs to be null/undefined:

const needsDetailPanel = rows.some((row) => row.customer === 'Michel');

return (
  <Box sx={{ width: '100%', height: 400 }}>
    <DataGridPro
      columns={columns}
      rows={rows}
      getDetailPanelHeight={getDetailPanelHeight}
      getDetailPanelContent={needsDetailPanel ? getDetailPanelContent : undefined}
    />
  </Box>
);

That way the grid will know that there is not detail panel and does not render the toggle

from mui-x.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.