Stop the Material UI Datagrid link column from redirecting onRowClicked

I am currently utilizing a Material UI Datagrid to showcase some data. Within one of the columns, there is a link that, when clicked, opens a URL in a new tab. I am facing an issue where I want to navigate to another page upon clicking on a row, but do not wish to do so if the link within the cell is clicked.

While I can simply disable click behavior for the entire cell containing the link, this is not the ideal solution. Is there a way to prevent the execution of onRowClicked when clicking on the Link itself, for instance?

Here is a simplified example of the setup I am working with:

<DataGrid 
    columns={[
        { flex: 200, field: 'name', headerName: 'Naam' },
        {
            flex: 250,
            field: 'url',
            headerName: 'Link',
            renderCell: (cell: GridCellParams) => (
                <Box width="100%" overflow="scroll">
                    <Link
                        href={cell.value}
                        target="_blank"
                    >
                        Click here
                    </Link>
                </Box>
            ),
        },
    ]}
    onRowClicked={(row) => {
        navigate(Routes.OTHER_PAGE.replace(':id', row.id))
    }}
    rows={rows}
/>

Answer №1

By including

onClick={(event) => event.stopPropagation()}
in the Link, the issue is resolved.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to persist input values in React Material UI's multiple select component even after the page refreshes or reloads?

I have a React Material UI multi-select feature in my application that displays a list of venues. Users can select multiple venues from this list. However, whenever I refresh the page after making selections, all my chosen venues disappear and the selected ...

Material-UI Date Selectors: Show the Date in (Month, Day, Year) Format -> (April 17, 2019)

If you're using the Material-Ui Pickers library, check out this link for more information: It appears that you can display the date as a (Month Day) string or as a (MM/DD/YYYY) format. However, I'm wondering if there is an option to display the ...

Is it possible to prevent the send button from being enabled until a message has been entered in the message field without using the onchange method in ReactJS

I just started learning React and I'm trying to achieve the goal of disabling the send button until a message is typed in the input field or displaying a popup without typing anything in the textfield. I attempted to use the onChange method for disabl ...

The mapStateToProps function in a Higher Order Component is receiving an OwnProps argument with a property that is not defined

I'm a new user of react-redux trying to connect a higher-order component to the react-redux store. In the mapStateToProps function, I'm using the ownProps argument to filter the state. However, the property I'm trying to use within OwnProps ...

React JS integrated with Stripe

I am in need of generating a token with Stripe.js within a React JS environment, however, I have been unable to find a straightforward solution. In a node.js setting, the process would typically look something like this: stripeClient.tokens.create({ ...

What steps do I need to follow to deploy my React application on GitHub?

After successfully creating my React project and pushing the full repository to GitHub through Visual Studio Code, I am now wondering how I can deploy my React project live on a server using the tools available on GitHub. Can anyone provide guidance on t ...

Is there a way to selectively import specific functions from a file in NextJs/React rather than importing the entire file?

Imagine this scenario: we have two files, let's call them File A - export const a = () => {} export const b = () => {} Now, consider importing this into File B - import { a } from 'path' When I tried running npm run analyze, it showe ...

Timer-triggered text fading animation in React/NextJS not functioning as expected

Being relatively new to React and NextJS, I've dedicated a solid 8 hours and significant research to crack this puzzle with no success! I'm attempting to create a component that randomly selects a word from an array, fades it in, then after a de ...

Having trouble getting my contact form to function with React and Express

I recently created a form using React which can be found at react_project/src/components/ContactForm/index.js const FormSection = () => { const [status, setStatus] = useState("Submit"); const handleSubmit = async (e) => { e.preventDefault(); ...

Sorting information in the React Native Section List

Working with React Native's SectionList and filtering data: data: [ { title: "Asia", data: ["Taj Mahal", "Great Wall of China", "Petra"] }, { title: "South America", data: ["Machu Picchu", "Christ the Redeemer", "C ...

"Exploring the methods to retrieve Firebase authentication error details and outputting the console log message along with

When I encounter an error in Firebase authentication, I want to display it in the console log. However, nothing is being logged and the catch block is not even getting executed. I am unsure about why this is happening and how to retrieve the error code and ...

Having trouble making changes to MUI TextFields once they've been filled in with data from an

My goal is to make MUI TextFields editable even after they have been filled with data from an API. The TextFields are getting populated successfully. I attempted using an onChange function, but it only allowed one additional character to be entered befor ...

Limiting the Material-UI text field of number type to accept only positive integers

Struggling to find a way to limit an MUI text field of type='number' to only accept positive numbers This is the TextField I am using: <TextField name={name} type={props.type || 'text'} label={props.label} helperText ...

Using immer JS to update a nested value has been successfully completed

What is the most efficient way to recursively change a value using a recursive function call in a Produce of Immer? The WhatsappState represents the general reducer type, with Message being the message structure for the application/db. type WhatsappState = ...

Generate nth-child selectors in a Material-UI component using props dynamically

I am currently working on customizing the Material UI slider component, specifically focusing on its marks prop to display the number of occurrences for each data object within the marks array. The desired appearance of the slider is illustrated in this i ...

Is there a method for uploading and viewing files from a server using the MERN stack?

Looking to create a functionality for users to upload various file types such as documents, presentations, and text files, save them to a database, and then view them from the server. Are there any recommended frameworks or npm modules to help with this ...

No visual changes with Material UI Switch

I have implemented Material UI's switch component in my multi-page app to change themes. However, I encountered a bug where the switch does not visually toggle from left to right (UI functionality is not working), even though the onChange event handle ...

Using React - send props directly to targeted child components

The Layout component code snippet is displayed below: import React, { useRef, useEffect, useState } from "react" import Navbar from "./Navbar" import "../styles/mains.scss" const Layout = ({ children }) ...

Is it possible to utilize the OnBlur prop based on a certain condition?

To display a component when the input is focused, follow the steps below: Click here for not focused state When you click on the text input, the component should appear like this: Click here for focused state The code snippet provided works correctly. ...

Next.js pages do not respond to event listeners

Something strange is happening in my Next.js project. I've implemented a header that changes color as the page scrolls using the useEffect hook: The hook in the Header component looks like this: React.useEffect(() => { window.addEventListener(&a ...