Set the GridToolbarQuickFilter text box to have an outlined style in Material UI v5

How can I customize the appearance of the GridToolbarQuickFilter textbox, such as outlining it? Ideally, I would like to accomplish this through theme.tsx, but I am open to any suggestions.

https://i.stack.imgur.com/H1Ojj.png

I have experimented with various methods, including tweaking classes in theme.tsx, but so far I have not been successful in changing its visual presentation.

Answer №1

To customize the variant of the quick filter, you can use

slotProps={{toolbar: {quickFilterProps: { variant: "outlined" }}}}
like demonstrated in the interactive example provided below.

import * as React from "react";
import Box from "@mui/material/Box";
import { DataGrid, GridToolbar } from "@mui/x-data-grid";
import { useDemoData } from "@mui/x-data-grid-generator";

const VISIBLE_FIELDS = ["name", "rating", "country", "dateCreated", "isAdmin"];

export default function CustomizedQuickFilterGrid() {
  const { data } = useDemoData({
    dataSet: "Employee",
    visibleFields: VISIBLE_FIELDS,
    rowLength: 100
  });

  const columns = React.useMemo(
    () =>
      data.columns.filter((column) => VISIBLE_FIELDS.includes(column.field)),
    [data.columns]
  );

  return (
    <Box sx={{ height: 400, width: 1 }}>
      <DataGrid
        {...data}
        columns={columns}
        slots={{ toolbar: GridToolbar }}
        slotProps={{
          toolbar: {
            showQuickFilter: true,
            quickFilterProps: {
              variant: "outlined",
              size: "small"
            }
          }
        }}
      />
    </Box>
  );
}

https://codesandbox.io/s/custom-quick-filter-variant-jqzdfv?fontsize=14&hidenavigation=1&theme=dark

If you wish to manage this customization through the theme, utilize the defaultProps feature of the theme shown here:

import * as React from "react";
import type {} from "@mui/x-data-grid/themeAugmentation";
import Box from "@mui/material/Box";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import { DataGrid, GridToolbar } from "@mui/x-data-grid";
import { useDemoData } from "@mui/x-data-grid-generator";

const VISIBLE_FIELDS = ["name", "rating", "country", "dateCreated", "isAdmin"];

const theme = createTheme({
  components: {
    MuiDataGrid: {
      defaultProps: {
        slots: {
          toolbar: GridToolbar
        },
        slotProps: {
          toolbar: {
            showQuickFilter: true,
            quickFilterProps: {
              variant: "outlined",
              size: "small"
            }
          }
        }
      }
    }
  }
});
export default function ThemedQuickFilterGrid() {
  const { data } = useDemoData({
    dataSet: "Employee",
    visibleFields: VISIBLE_FIELDS,
    rowLength: 100
  });

  const columns = React.useMemo(
    () =>
      data.columns.filter((column) => VISIBLE_FIELDS.includes(column.field)),
    [data.columns]
  );

  return (
    <ThemeProvider theme={theme}>
      <Box sx={{ height: 400, width: 1 }}>
        <DataGrid {...data} columns={columns} />
      </Box>
    </ThemeProvider>
  );
}

https://codesandbox.io/s/themed-quick-filter-variant-3kzx7t?fontsize=14&hidenavigation=1&theme=dark

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

Generating a File that Imports Components and Instantly Exports Them Once More

Having trouble with this code. Initially, I had: // file 1 import Box from '@/components/Box' import Popup from '@/components/Popup' const MDXComponents = { Box, Popup } // using MDXComponents somewhere in file 1 Now, to manage t ...

Step-by-step guide on how to stop CDK Drop depending on a certain condition

I'm trying to figure out how to disable dropping using CDK based on certain conditions. Specifically, I want the drop functionality to be disabled if the list I'm attempting to drop into is empty. I haven't been able to find a solution withi ...

Error encountered when attempting to insert data into a PostgreSQL database using Node.js and Sequelize

I'm currently using the node sequelize library to handle data insertion in a postgress database. Below is the user model defined in the Users.ts file: export class User extends Sequelize.Model { public id!: number; public name: string; public ...

encountering an issue following the initial setup using create-next-app

After searching on Stack Overflow and finding no answers, I am posting this question again. When I create a new project in Next.js using npx create-next-app project-name --ts and run npm run dev without making any changes to the source code, I encounter t ...

Add a custom design to the Material UI menu feature

I am currently trying to implement a custom theme using the following code: import Menu from '@material-ui/core/Menu'; import { createStyles, withStyles, Theme } from '@material-ui/core/styles'; const myMenu = withStyles( ( theme: The ...

Next.js does not recognize the term 'localstorage'

I am currently in the process of transitioning an application from React to Next Interestingly, in React, I encounter no errors with this particular code snippet: let [authTokens, setAuthTokens] = useState(() => localStorage.getItem('authTokens&ap ...

Empty placeholder feature in Material UI Autocomplete

Currently, I am working on a project that involves using Material UI Autocomplete. At the beginning, the option list is empty. However, upon input change, the list gets populated with data. During this initial empty state, I would like to display a placeh ...

Combining Switch components with a universal NoMatch element in React Router Version 4

My application is currently divided into three main parts: Frontend Administration Error Each part, including Frontend, Administration, and Error, has its own unique styling. In addition, both the Frontend and Administration components have their own S ...

Can all objects within an interface be iterated through in order to retrieve both the key and its corresponding value?

I have created an interface that is capable of accepting a variety of search criteria and then passing it to a service that will incorporate those values into the service URL. I am wondering if there is a way to iterate through all the objects in the inter ...

Arrange a FlatList according to a specific value within its contents

I'm sending information to my FlatList through the following code snippet: <FlatList data={pubData} renderItem={({ item }) => ( <Item id={item.id} name={item.name} lat={item.lat} long={item.long} deviceL ...

Testing the integration of socket.io with Angular through unit tests

Currently, I am in the process of unit testing an angular service within my application that is responsible for creating a socket.io client. The structure of my service can be seen below: export class SocketService { private name: string; private host ...

Creating a circular frame for your image to use as a Facebook profile picture

In the process of developing an input feature that allows users to upload file images for avatar changes, similar to Facebook's functionality. However, I am aware that Facebook utilizes a circular area for avatars and enables users to adjust the image ...

how to customize nested styles in material-ui

I am facing an issue with a basic Material-UI component <Chip avatar={ <Avatar> <TruckIcon color='primary' /> </Avatar> } label={name} color='primary' /> ...

Using ReactJS: Executing a parent's setState() function from within this.props.children

I am currently working on a parent component that is utilized by the React Router. The render function of this component looks like this: render() { return ( <Grid> <Breadcrumb> {this ...

Utilizing Webpack to Load Jquery

I developed an npm package named ABC, which I am currently testing in a create react app. This package utilizes Webpack and has a dependency on another package called DEF, which ultimately relies on Jquery. However, upon loading my create react app, I enco ...

What steps can I take to stop Vetur and TypeScript from displaying duplicate TypeScript warnings in VSCode?

I have a Vue2 project using TypeScript in VSCode with Vetur and TypeScript extensions installed. Whenever there is a TypeScript warning, both the TypeScript and Vetur overlays show duplicate warnings. Example of duplicate warnings Also, the intellisense ...

When clicking initially, the default input value in an Angular 2 form does not get set

I am currently learning angular2 as a beginner programmer. My goal is to create a form where, upon clicking on an employee, an editable form will appear with the employee's current data. However, I have encountered an issue where clicking on a user f ...

Progressively Loading Linear DataGrid Cells in Material-UI

I am trying to include a new column called Filled Quantity in my table. After going through the documentation, I am unsure how to achieve this. It seems like I might need to use renderCell while setting up the column, but I am not sure how to go about it. ...

What is the best way to incorporate Typescript React Components across various projects?

I'm venturing into developing an npm package that involves several react components implemented with typescript. As a newcomer to react and npm, I apologize if my query seems basic. Despite researching online, there isn't much information on this ...

Displaying data-table with only the values that are considered true

Right now, I am utilizing the AgReact table to exhibit data fetched from my endpoints. The data-table is functioning properly, however, it seems to be unable to display false values received from the endpoints on the table. Below are the snippets of my cod ...