Is there a way to customize the color of the icons on material-table for the actions of onRowAdd, onRowUpdate, and onRowDelete

I recently experimented with the material-table library to perform basic CRUD operations. Utilizing onRowAdd, onRowUpdate, and onRowDelete, I was able to incorporate icons for each function. However, I am interested in changing the color of these icons. Can anyone provide guidance on how to achieve this?

In my table, there are specific icons – add, edit, delete – that I would like to customize with different colors.

For reference, here is the link to my codesandbox.

App.js file content:

import React, { useState } from 'react';
import './App.css';
import MaterialTable from 'material-table'

const empList = [
  { id: 1, name: "Neeraj", email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90fef5f5e2f1fad0f7fdf1f9fcbef3fffd">[email protected]</a>', phone: 9876543210, city: "Bangalore" },
  { id: 2, name: "Raj", email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5624373c16331b373f3a78353d39">[email protected]</a>', phone: 9812345678, city: "Chennai" },
  { id: 3, name: "David", email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f69297809f92c5c2c4b697989f9ad895999b">[email protected]</a>', phone: 7896536289, city: "Jaipur" },
  { id: 4, name: "Vikas", email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ff9e6e4eefcb8bacfe8e2eee6e3a1ece0e2">[email protected]</a>', phone: 9087654321, city: "Hyderabad" },
]

function App() {

  const [data, setData] = useState(empList)
  const columns = [
    { title: "ID", field: "id", editable: false },
    { title: "Name", field: "name" },
    { title: "Email", field: "email" },
    { title: "Phone Number", field: 'phone', },
    { title: "City", field: "city", }
  ]


  return (
    <div className="App">
      <h1 align="center">React-App</h1>
      <h4 align='center'>Material Table with CRUD operation</h4>
      <MaterialTable
        title="Employee Data"
        data={data}
        columns={columns}
        editable={{
          onRowAdd: (newRow) => new Promise((resolve, reject) => {
            const updatedRows = [...data, { id: Math.floor(Math.random() * 100), ...newRow }]
            setTimeout(() => {
              setData(updatedRows)
              resolve()
            }, 2000)
          }),
          onRowDelete: selectedRow => new Promise((resolve, reject) => {
            const index = selectedRow.tableData.id;
            const updatedRows = [...data]
            updatedRows.splice(index, 1)
            setTimeout(() => {
              setData(updatedRows)
              resolve()
            }, 2000)
          }),
          onRowUpdate:(updatedRow,oldRow)=>new Promise((resolve,reject)=>{
            const index=oldRow.tableData.id;
            const updatedRows=[...data]
            updatedRows[index]=updatedRow
            setTimeout(() => {
              setData(updatedRows)
              resolve()
            }, 2000)
          })

        }}
        options={{
          actionsColumnIndex: -1, addRowPosition: "first"
        }}
      />
    </div>
  );
}

export default App;

Answer №1

If you want to customize the icons and apply your own styles, you can do so by adjusting the icons props. This involves providing an object where each key represents a specific operation type (Add, Edit, Delete,...) and the corresponding value is the desired icon component. For more information, please refer to the comprehensive list of props available here.

<MaterialTable
  {...props}
  icons={{
    Edit: () => <EditIcon style={{ color: "orange" }} />,
    Delete: () => <DeleteIcon style={{ color: "red" }} />
  }}
>

Check out this Live Demo

https://codesandbox.io/s/67159866how-would-i-change-the-custom-color-of-material-table-icons-of-onrowadd-onrowup-84bjr?file=/src/App.js

Answer №2

Simply put, just examine the page and pick out the icon you like. Then, copy its style name from the Styles Tab.

Next, open up your App.css file and create a new style using the icon's style name that you found in the inspect-styles section. From there, you can customize the color to your liking.

Give it a try!

In your App.css File, Insert the following code:

.MuiIconButton-colorInherit {
    color: blue;
}

You can change the color to whatever you prefer.

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

Issues arise with the functionality of Datatables when attempting to implement a

I am trying to sort the "Date Created" column in my table in descending order of the latest date. I found a forum that suggested using the datetime datatable sorting plugin, but it didn't work as expected. Can someone help me solve this issue? Below a ...

Exploring Jasmine's Powerful Spying and Mocking Capabilities in JavaScript Prototypes

Hey everyone, I need some help with a JavaScript issue. So, I have a file named FileA.js which contains a prototype called FileAObject.prototype along with a function named funcAlpha(). Here's a snippet of what it looks like: File = FileA function s ...

Determining the appropriate generic type in Typescript

In my code, there is a method designed to extend an existing key-value map with objects of the same type. This can be useful when working with database query results. export function extendWith< T extends { id: string | number }, O = | (T[" ...

Refresh the jQuery Carousel when the window is resized to switch the orientation from vertical to horizontal

I am in the process of creating a gallery for a responsive layout, utilizing jQuery Riding Carousels for the thumbnails. You can find more information about it here. One issue I am encountering is that when the window size shrinks to be smaller than 1024p ...

The service 'containerregistry.googleapis.com' has not been activated for the user 'project:next'

After dockerizing my Next.js app, I attempted to deploy it on Google Cloud. However, during the process of pushing the docker image to the registry, I encountered the following error: Unknown: Service 'containerregistry.googleapis.com' is not e ...

Using Multiline Strings for Arguments

Is there a way to successfully pass multi-line strings containing spaces and tabs as a parameter to an express server? Below is the Express.js code snippet which accepts the parameter: app.get('/:prompt', async (req, res) => { ...

Can the combination of pure HTML+JS applications with .NET webservices be both feasible and safe?

Our recent projects have utilized MVC5 with AngularJS, Ninject, Bootstrap, and various other technologies. However, we found that these applications required significant time to fix bugs and add features due to unnecessary complexity. Would it be feasible ...

The type '0 | Element | undefined' cannot be assigned to the type 'Element'

I encountered the following error: An error occurred when trying to render: Type '0 | Element | undefined' is not assignable to type 'Element'. Type 'undefined' is not assignable to type 'ReactElement<any, any>&apo ...

Tips for Providing Real-Time Data for a Dynamic Chart in d3

I have a line chart sample from D3, and the issue I'm facing is that I need to continuously feed live data from a server at certain time intervals and use D3 to draw the chart based on this dynamic data. Despite my efforts to search for a solution, I ...

I'm having trouble incorporating react-bootstrap into my NextJS project

Struggling to integrate React-bootstrap into NextJS I've included 'bootstrap/dist/css/bootstrap.min.css' in _app.tsx and installed it with yarn add Seeking assistance as I am new to this technology import Container from 'react-bo ...

Using React.PureComponent, the list component efficiently renders each item with optimized performance

We've developed a reusable list component in ReactJS. To address performance concerns, we decided to incorporate the shouldComponentUpdate method to dictate when our list component should re-render. public shouldComponentUpdate(nextProps: TreeItemInt ...

The functionality of sending form data via Express.js router is restricted

In my current project, I am developing a basic CRUD functionality in express. My goal is to utilize the express.Router() to transmit form data via the HTTP POST method. The form structure on the browser appears as follows: form.png The process was flawle ...

ReactJS table does not refresh when the data in the state is updated

Currently, I am engrossed in grasping the concepts of ReactJS and its reactive nature. To get myself started, I decided to work on a straightforward example. I crafted a component that holds some data as state, intending to exhibit this information within ...

Can't figure out why the BackgroundImage URL from process.env isn't appearing on my website

Having trouble setting a background image on my website that connects with my backend to determine which image should appear. However, in some cases, the image isn't showing up. When attempting to add a background image using the code below within a ...

Utilizing a self-invoking function to incorporate JavaScript

In my role, I am responsible for managing a Content Management System (CMS) used by developers to create content that involves JavaScript. In the past, we placed the content in an iFrame for containment purposes; now, it operates as a single-page client-si ...

getting v-model value updated when clicking button

How can I update the value of v-model DataJournals.Description in a looping data when a button is clicked? This is what I have attempted: template <tr v-for="(DataJournals, index) in DataJournal" :key="DataJournals.value"> <td> & ...

jQuery is used to make an object fade out once another object has been moved into place

As I delve into the world of jQuery, I've decided to create a simple Super Mario imitation. The concept is to control Mario using arrow keys and fade out mushrooms once Mario reaches them. However, my attempts at achieving this result have not been su ...

Obtain Outcome from a Nested Function in Node.js

I'm grappling with the concept of manipulating the stack in JS and hoping this exercise will provide some clarity. Currently, I'm attempting to create a function that makes a SOAP XML call, parses the data, and returns it when called. While I c ...

I possess a list of unique identifiers and require the ability to either update an existing object within an array contained in a MongoDB document, if it exists,

I am facing a challenge in updating a specific element within an array in a MongoDB document. I have multiple IDs of that array and need to update the matching element using those IDs. data= [ { "planId" : "plan_FVNvrmjWT7fRDY", "startTime": ...

Creating an image rollover effect when hovering between two images

I am currently working with React and trying to change 2 images by hovering over them. Here is what I have accomplished so far: Card.js <div className="image-wrapper"> <img src={sprites.front_default} className="image" a ...