Code Monkey home page Code Monkey logo

Comments (8)

sorinpav avatar sorinpav commented on June 28, 2024 1

@michelengelen I edited the link in the main description. This should now work, hopefully. I'll add it here for visibility as well. https://stackblitz.com/edit/react-bpfeec?file=Demo.js
Thanks for the help!

from mui-x.

DanailH avatar DanailH commented on June 28, 2024 1

I think this relates to this PR #8672. The goal of the PR is to rework the way that the onRowsScrollEnd behaves.
The main problem with the name of the callback is that it implies that it will only be called if the user scrolls which is not the case - it's called whenever the "scroll" reaches the bottom which in the case of having fewer rows than the viewport can take will result in the callback being called.
Hope that this explains the issue.

I'll close this in favor of #4371 as it is essentially a duplicate.

from mui-x.

michelengelen avatar michelengelen commented on June 28, 2024

Hey @sorinpav I am not able to open your live example. It is stuck at connecting to dev server.\ Could you check if there is something wrong with it and get back to us? Without the example we will not be able to help you with this. Thanks! 🙇🏼

from mui-x.

sorinpav avatar sorinpav commented on June 28, 2024

@michelengelen I will have a look, thanks for letting me know. I'll edit the link in a few minutes.

from mui-x.

michelengelen avatar michelengelen commented on June 28, 2024

OK, thanks for fixing that example.
The behavior of the event is as intended.
What exactly are you trying to accomplish with this? Maybe I can help to find another way of doing this.

From your description it seems when filtering and the results return a small enough amount of rows the onRowsScrollEnd gets triggered and you fetch new data from your backend, is that about right?

from mui-x.

sorinpav avatar sorinpav commented on June 28, 2024

@michelengelen yes, exactly, and we would wish to be able to fetch results from the server only when intentionally scrolling down, not when filtering.

from mui-x.

sorinpav avatar sorinpav commented on June 28, 2024

Currently, we added a workaround with a useEffect that listens to the statechange event, and gets the number of visible rows by using gridExpandedRowCountSelector, a code shim looks something like this:

  import {gridExpandedRowCountSelector} from "@mui/x-data-grid-premium";

  const [visibleRows, setVisibleRows] = useState();

  useEffect(() => {
    apiRef?.current?.subscribeEvent?.("stateChange", () => {
      const count = gridExpandedRowCountSelector(apiRef.current.state);
      setVisibleRows(count);
    });
  }, [apiRef, apiRef?.current?.subscribeEvent, apiResults]);

and then using visibleRows to update X in the "X results displayed" string above the dataGrid, but we see this as a workaround since the results fetching from the server still happens, but at least we have that number reflecting how many rows are actually seen on screen.

On the performance side of things, it's extra requests to the server that the user hasn't asked for, so that is why we would prefer the event to not trigger, because we haven't solved that with our workaround.

Posting the code here to help others who may encounter the same issue, and don't mind the extra requests.

@michelengelen if you have any better ideas please shout up! Thanks for the help!

from mui-x.

sorinpav avatar sorinpav commented on June 28, 2024

The behavior of the event is as intended.

Also, I understand that the event triggers when it thinks it's reached the end of the list of rows, but I don't think it's correct for that to happen when the user is just filtering results, as of course you're going to reach the end of the list if you're looking for one particular result only.

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.