Deactivate the rows within an Office UI Fabric React DetailsList

I've been attempting to selectively disable mouse click events on specific rows within an OUIF DetailsList, but I'm facing some challenges. I initially tried overriding the onRenderRow function and setting CheckboxVisibility to none, but the row remained clickable. Next, I attempted wrapping a div around the row and disabling it, only to discover that React divs do not have a disabled attribute. Can anyone offer assistance with this issue?

<DetailsList
    items={this.state.items}
    columns={this.getColumns()}
    selection={this.selection}                    
    selectionMode={SelectionMode.multiple}
    onRenderRow={this.renderRow.bind(this)}>
</DetailsList>

private renderRow(props: IDetailsRowProps, defaultRender: any){
    let state = this.state.items[props.itemIndex].workflowState;
    if(state === "disabledState"){
        //props.checkboxVisibility = CheckboxVisibility.hidden; <- Not working
        // return <div disabled={true}>{defaultRender(props)}</div> <- Not working
        return defaultRender(props);
    }
    else{
        return defaultRender(props);
    }
}

Solution:

this.selection = new Selection({ canSelectItem: this.canSelectItem.bind(this), onSelectionChanged: this.clickRow.bind(this) });

<DetailsList
    items={this.state.items}
    columns={this.getColumns()}
    selection={this.selection}                    
    selectionMode={SelectionMode.multiple}
    onRenderRow={this.renderRow.bind(this)}>
</DetailsList>

private canSelectItem(item: any): boolean {
    return item.state !== "disabledState";
}

Answer №1

After further investigation, I have discovered the solution to my query once again. It turns out that the Selection object contains a canSelectItem function which allows for checking whether a user should be able to select specific items. This function is designed to return a boolean value and requires the currently selected item from the array in order to check values conveniently. I have made the necessary modifications to my code above, implementing the solution accordingly.

Answer №2

One possible approach is to attach a function to the onClick event and then use either preventDefault or stopPropagation. You can also adjust the CSS to eliminate the cursor effect so that it resembles a standard HTML tag.

For example:

if(state === "disabledState"){  
  let onClickFunc = this.preventClick.bind(this);
} else {
  let onClickFunc = this.normalClick.bind(this);
}

return <div onClick={onClickFunc}>{defaultRender(props)}</div>

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

Using styled-components to enhance an existing component by adding a new prop for customization of styles

I am currently using styled-components to customize the styling of an existing component, specifically ToggleButton from material ui. However, I want my new component to include an additional property (hasMargin) that will control the style: import {Toggle ...

Utilizing the DirectusImage tag for a stylish background effect

I'm new to Directus and I need help styling a card with a background image from a Directus Image. Can anyone guide me on how to achieve this? Here's what I have tried: <Card style={{backgroundImage:"url({someColletion.image.id})" &g ...

Unlock the power of Formik for extracting values from Material UI Select Fields

Excuse me, I'm trying to grasp and accomplish something with Formik. I have two select fields and I want to pass their selected values to the formik value. Essentially, they retrieve a list of countries and their respective regions from the CountryAr ...

The property "x" is not found within the type '(props?: any) => ClassNameMap<"x">'

Creating styles based on a parameter involves the following steps: const useStyles = (isLayoutReadOnly = false) => makeStyles((theme: Theme) => { return { x: { margin: theme.spacing(0, 0, 1, 0), marginLeft: !isLayoutRea ...

The issue of javascript Map not updating its state is causing a problem

I've encountered an issue where my components are not re-rendering with the updated state when using a map to store state. const storage = (set, get) => ({ items: new Map(), addItem: (key, item) => { set((state) => state.items ...

Utilize react-native-image-picker and axios to effortlessly upload an image to S3 via a presigned URL

I am currently working on implementing a function to upload an image using a pre-signed URL. The issue I am facing is that although the upload process is successful when selecting an image from the IOS simulator, the file appears to be corrupted and cannot ...

Tips for concealing information within the column labeled company Name with respect to the field designated as Company Name

I am currently working on an Angular 7 app and I am facing an issue: I cannot hide the data in the column for Company Name. The field "Name" in the report control JSON is labeled as Company Name. The report control is a table that contains various fields ...

Unable to make changes to the document

Having trouble updating a document by ID using mongoose and typescript. I'm testing the api and passing the id as a parameter. I've experimented with different methods of updating by ID, but for some reason, it's not working. Can update by ...

Highlighting the content within Material-UI's <Dialog> using ReactJS without affecting the entire webpage

I have an issue in my ReactJS project with the <Dialog> component from Material-UI (http://www.material-ui.com/#/components/dialog). When I open the <Dialog> and press command + a on my Mac, it highlights the entire page instead of just the con ...

Access a designated webpage with precision by utilizing Routes in Angular

Is it possible to display a different component in Angular routing based on a condition in the Routing file? For example, if mineType is equal to "mino", can I navigate to another component instead of the one declared in the Routing? Should I use Child ro ...

What is the best way to mark a MenuItem as active within a Material UI Drawer component?

Here is the code snippet I am working with: <Drawer docked = {false} width = {330} open = {this.state.drawerOpen} onRequestChange = {(drawerOpen) => this.setState({drawerOp ...

Personalize your Material UI ToolTip

I am currently working on customizing the material ui tooltip for React Storybook. After attempting to adjust various CSS properties such as width, height, and background color, I have not been successful in seeing these changes reflected. import * as Re ...

provide the React Context value as an argument

I'm facing an issue where I cannot pass a context value as a parameter when calling a function from another file. The code I have is shown below: import React, { useContext } from React import { AuthContext } from "src/contexts/AuthContext"; ...

Deactivate automatic logins following a password reset with the clerk tool

Looking for help with implementing a "forgot password" feature in my Next.js project using Clerk. I've been following the official documentation provided by Clerk, but ran into an issue where users are automatically logged in after resetting their pas ...

Having trouble with the onLoadingComplete props in the Next.js Image component?

Is there a way to properly retrieve the naturalWidth and naturalHeight using the onLoadingComplete props? I tried following the documentation on https://nextjs.org/docs/api-reference/next/image#onloadingcomplete but it doesn't seem to be working. Am I ...

Issue encountered when using await in Tensorflow.js sample code with TypeScript

After going through the official tensorflow.js documentation, I attempted to test this example using typescript with tensorflow.js While trying to execute the code snippet provided in the tensorflow.js documentation, I encountered an error related to the ...

Finding out if an array is empty or not in Reactjs: A Quick Guide

I am currently working with Reactjs and Nextjs. I am using axios to fetch data, and I need a way to determine if the array (students.data) is empty before running a map or loop. How can I achieve this? Here is the code snippet I am working with: const [stu ...

When you duplicate the React State object and make changes to the copied object, it directly affects

When attempting to duplicate a state object, I noticed that the state object is being modified directly in the code snippet below: @boundMethod private _onClickDeleteAttachment(attachmentName: string): void { console.log("_onClickDeleteAttachment | th ...

Leveraging react-redux-firebase for integrating cloud functions into React JS applications

I recently started learning React JS and I'm working on a project where I need to display data from cloud firestore. To fetch the data, I am utilizing react-redux-firebase. It's all working smoothly so far. However, now I want to switch to retrie ...

Step-by-step guide on programmatically closing the Material-UI DropDownMenu

http://www.material-ui.com/#/components/dropdown-menu Having encountered a styling issue, I was compelled to rearrange the order of components within my material-ui DropdownMenu. Nevertheless, some buttons (renderNavLink) are now failing to close the Dro ...