Deactivate an entire row in the MUI DataGrid

My task involves organizing the data into columns:

const columns: GridColDef[] = [
  {
    field: "firstName",
    headerName: "First name",
    width: 150,
    editable: true,
  },
  {
    field: "lastName",
    headerName: "Last name",
    width: 150,
    editable: true,
  },
  {
    field: "age",
    headerName: "Age",
    type: "number",
    width: 110,
    editable: true,
  },
  {
    field: "fullName",
    headerName: "Full name",
    description: "This column has a value getter and is not sortable.",
    sortable: false,
    width: 160,
    valueGetter: (params: GridValueGetterParams) =>
      `${params.row.firstName || ""} ${params.row.lastName || ""}`,
  },
];

The actual data placed within rows consists of:

const rows = [
  { id: 1, lastName: "Snow", firstName: "Jon", age: 14 },
  { id: 2, lastName: "Lannister", firstName: "Cersei", age: 31 },
  { id: 3, lastName: "Lannister", firstName: "Jaime", age: 31 },
  { id: 4, lastName: "Stark", firstName: "Arya", age: 11 },
  { id: 5, lastName: "Targaryen", firstName: "Daenerys", age: 25 },
  { id: 6, lastName: "Melisandre", firstName: null, age: 150 },
  { id: 7, lastName: "Clifford", firstName: "Ferrara", age: 44 },
  { id: 8, lastName: "Frances", firstName: "Rossini", age: 36 },
  { id: 9, lastName: "Roxie", firstName: "Harvey", age: 65 },
];

I have implemented an onRowClick functionality which captures the clicked row data for further processing.

The requirement is to disable a row if the individual's age is over 30.

(visual reference provided in this image: link)

For the code implementation, please refer to the following link: sandbox

Answer №1

Just a bit further, you're almost there! To handle the behavior as needed, make sure to read the exact parameter. Adjust your onRowClick function like this:

onRowClick={(params: GridRowParams) => {
  if (params.row.age > 30) {
    console.log("Greater than 30. Selected age is", params.row.age);
    return;
  }
  console.log("Lower than 30. Selected age is", params.row.age);
}}

You can check out the full code with modifications made by me in this Sandbox.

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

Efficiently integrating Firebase Functions with external sub path imports beyond the project's

I encountered an issue in my firebase functions project with typescript. The problem arises when I use types from outside the project with sub path imports, causing the build files to become distorted. Instead of having main:lib/index.js, I have main:lib/ ...

Issue: The element '[object Object]' is of type 'object', which is not supported by NgFor. NgFor only works with Iterables like Arrays. - Problem encountered in an Ionic Project

I'm currently working on retrieving my user's username from Firebase Firestore Database using Ionic and AngularFire. I have implemented the valueChanges() method to obtain the observable and am trying to process it using an async pipe. However, u ...

Inheritance-based type inference

I have created a class hierarchy to manage inheritance in my code. Here is an example of how it looks: class A { clone(): A { return new A() } methodA() { return this.clone() } } class B extends A { clone(): B{ return new B() } ...

Utilizing Material-UI checkboxes in combination with ReactJS and Redux for enhanced functionality

I am currently working on a project where I need to display selected checkbox items using material-ui's checkbox component. Although I have successfully displayed the items with checkboxes, I am facing difficulties in displaying the selected items. ...

Looking for a top-notch type definition management solution for Typescript, similar to tsd?

When considering the use of Typescript, the resolution of type definition files (*.d.ts) is essential. There are various systems for managing Typescript definition files, including: tsd typings @types It seems that tsd is the oldest system and the orig ...

Encountering an issue with a MEAN application using Angular 2: The error message states "Cannot read property

As a first-time application developer, I am working on creating a system to manage Client profiles. Utilizing the Angular tour of heroes for the basic structure, I integrated mongodb and express components sourced from various online platforms. However, I ...

Customize the position of nodes and their descendants in a d3 tree chart by setting specific x and y coordinates

I am in need of a d3 tree structure that looks like this. https://i.sstatic.net/X6U3u.png There are two key points to understand from the image above: Headers will have multiple parents(wells). I need to be able to drag and drop links connecting w ...

Is it necessary to declare parameters for the super class constructor in Typescript React? If so, what would those parameters be?

I'm struggling to understand the specifics of the constructor in this code. Can anyone clarify what arguments the constructor for super() and constructor() should have? import * as React from "react"; import styles from "./ScriptEditor.module.scss"; ...

Example of Using Bluebird in a Chain of Catch and Then Functions

I am struggling to understand how promises work in my code flow setup. I want to create a register function with multiple steps, but I'm unsure of what is achievable and what is not. Imagine I have a register function where I need to: register a u ...

What is the most efficient method for transforming files using a heroku deployed application?

I'm currently developing a Discord bot deployed on Heroku that has a function to convert video files to .mp4 format and then embed the file in a reply message. When running the function locally, everything works fine. However, when running it on the d ...

Preparing JSON data for use with chart.js leveraging Angular 4 observables

Struggling to make sense of this dilemma, I find myself unable to crack the code. The data retrieved from my API is structured in the following format: "data": [ { "sr_count": 91, "month_name": "October", "month_num": 10, ...

Persistent error caused by unresponsive Tailwind utility functions

Currently, I am working on a Next.js application and encountered a strange error while adjusting the styling. The error message points to a module that seems to be missing... User Import trace for requested module: ./src/app/globals.css GET /portraits 500 ...

The function type '() => JSX.Element' cannot be assigned to the type 'ReactNode'

I am encountering an issue while trying to display a component using an object. The code is throwing an error: const Login = () => <>login</> const publicRoutes = [ { path: '/login', component: Login } ] function AppR ...

Incorporate the class directly into the datepicker input element in a React JS component

Adding a class directly to the input element is what I am trying to achieve here.https://i.sstatic.net/qGGwD.png The class MuiInputBase-input needs to be added. This code pertains to a date picker. import { DateTimePicker, MuiPickersUtilsProvider } from & ...

Ensure that an input control consistently displays the value it is linked to

Here is the code snippet of the component: @Component({ template: ` <form> <label>Enter your name:</label> <input #name name="name" [ngModel]="firstName" (change)="onNameChange(name.value)"> </form> <p>Y ...

Utilizing HttpClient in a static method service with Angular

One of my services contains a static method that I use for some initialization treatment. Within this method, I need to retrieve data from a web service @Injectable() export class FeaturesInitializationService { static allowedFeaturesModul ...

HTML: Mark the chosen hyperlink or tag

In my HTML page, I am looking to keep the link selected when it is clicked on. Here is the initial HTML code: <table class="main-dev"> <tr> <td> <a class='titleForm' style="cursor:pointer"> ...

Obtaining database information and utilizing setValue or patchValue

One way to retrieve data from a database and populate it into an input box is shown below: Retrieving service getStudentAddress() { const id = sessionStorage.getItem('userId'); return this.http.get('http://localhost:8080' + '/s ...

Generate a basic collection of strings from an object

Looking at this object structure Names = [ { group: 'BII', categories: null }, { group: 'GVL', categories: [] } ]; I ...

Troubleshooting Angular Toaster issues with TypeScript

After downloading the angular-toaster.d.ts file from Nuget and setting up a notification service, everything seems error-free, but the notification service is not functioning as expected. export class notificationService { constructor(private toaster ...