How to Eliminate Lower Borders from DataGrid Component in Material UI (mui)

I've been trying to customize the spacing between rows in a MUI Data Grid Component by overriding the default bottom border, but haven't had much success. I've experimented with different approaches such as using a theme override, adding a className with the border property set to none, utilizing the sx feature, and even creating a custom index.css stylesheet. Any assistance on this matter would be highly appreciated.

Below is my component: component.tsx

   <div className = {classes.ListTable}>
       <DataGrid
           sx={{
               border: 0, // also tried setting to none 
               borderRadius: 2,
               p: 2,
               minWidth: 300,
           }}
           rows={rows}
           columns={columns}
           pageSize={5}
           rowsPerPageOptions={[5]}
           checkboxSelection
           disableSelectionOnClick
           classes={{ root: classes.MuiTableCell}}
       />
    </div>

Here are the methods I have attempted so far without success:

theme.tsx

const theme = createTheme({
  ...
   overrides: {
       DataGrid: {
           root:{
               border: 'none',
           }
       }
   }
});

index.css

.MuiPaper-root-MuiDrawer-paper, 
.MuiDataGrid-footerContainer, 
.MuiDataGrid-root, 
.MuiDataGrid-row, 
.MuiDataGrid-column, 
.MuiDataGrid {
    border: 0 !important;
}

styles.tsx

  ListTable: {
      borderBottom: "none",
      border: 0,
  },
   MuiTableCell: {
      borderBottom: "none",
      outline: 0,
      borderColor: "10px solid red",
      color: theme.palette.text.primary,
   }

If you have any suggestions or solutions, please feel free to share - your help will be greatly appreciated. Thank you in advance.

Answer №1

Dealing with the same issue, I managed to find a solution that did the trick. It may not be the cleanest code, but it gets the job done. Simply insert the following snippet into your styles.tsx.

grid: {
'&>.MuiDataGrid-main': {
  '&>.MuiDataGrid-columnHeaders': {
    borderBottom: 'none',
  },

  '& div div div div >.MuiDataGrid-cell': {
    borderBottom: 'none',
  },
}}

Answer №2

Recently, I discovered a more concise method to eliminate all borders from a MUI's datagrid table while keeping the borders of other components intact.

<DataGrid
  columns={columns}
  rows={rows}
  sx={{ '&, [class^=MuiDataGrid]': { border: 'none' } }}
  />
  • & targets the DataGrid itself, removing the table's outer border,
  • [class^=MuiDataGrid]' utilizes an attribute selector to select every child element within the grid with a class attribute starting with MuiDataGrid

Answer №3

When working on a MUI v5 project, I successfully implemented the following code to remove main borders.

const customizedTheme = createTheme({
    components: {
        MuiDataGrid: {
            styleOverrides: {
                root: {
                    border: 'none'
                }
            }
        }
    }
})

Answer №4

Customizing the datagrid in MUI v5 allows for a unique styling approach.

  const StyledDataGrid = styled(DataGrid)(({ theme }) => ({
    border: 0,
    color: '#757575',
    fontFamily: 'Lato',
    WebkitFontSmoothing: 'auto',
    letterSpacing: 'normal',
  '& .MuiDataGrid-row': {
   width: '1191px',
   height: '34px',
  background: '#FFFFFF',
  borderRadius: '27px',

},
'& .MuiDataGrid-iconSeparator': {
  display: 'none',
},
'& .MuiDataGrid-columnHeaders': {

  width: '1191px',
  minHeight: '34px',
  background: '#D5DFED',
  borderRadius: '20px',

},
'& .MuiDataGrid-columnHeaderTitle': {
  fontWeight: 700,
  fontSize: '14px', minHeight: '34px',
},
'& .MuiDataGrid-row.Mui-selected': {
  background:' #FFFFFF',
  border: '1px solid #73A0FF',
  borderRadius:' 27px',
},
'& .MuiDataGrid-cell': {
  fontFamily:'Lato',
  fontWeight: 400,
  fontSize: '14px',
  lineHeight: '17px',
  color: '#757575',
  boxSizing: 'none',borderBottom: 'none',
},
'& .MuiPaginationItem-root': {
  borderRadius: 0,
}
}));

Answer №5

For those still struggling with this issue, here's a straightforward solution that works perfectly using MUI v5 & v6:

<DataGrid 
sx={{ 
'&>.MuiDataGrid-main': {
                            '&>.MuiDataGrid-columnHeaders': {
                                borderBottom: 'none'
                            },

                            '& div div div div >.MuiDataGrid-cell': {
                                borderBottom: 'none'
                            }
                        }
}}

</> 

Answer №6

I recently experimented with adding a static css file to my project along with a class="peaches" on a parent <div> in order to maintain logical styles without relying on !important.

Fortunately, this approach worked perfectly as it successfully removed all the borders I needed to eliminate (such as those between rows and around headers, footers, and the table itself):

.peaches .MuiDataGrid-root {
  border: 0;
}
.peaches .MuiDataGrid-cell {
  border: 0;
}
.peaches .MuiDataGrid-columnHeaders {
  border: 0;
}
.peaches .MuiDataGrid-footerContainer {
  border: 0;
}

By utilizing CSS selector specificity for its intended purpose, there is no need for using !important. The Styles inspector in Chrome DevTools indicates the source of the borders, allowing you to determine the selector count utilized by MUI and ensuring that your CSS overrides them accordingly.

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

Empowering Components with React Hooks

I am currently in the process of transitioning from using class components to React hooks with the Context API. However, I am encountering an error and struggling to pinpoint the exact reason for it. Here are my Codes: // contexts/sample.jsx import React ...

React Image Slider not loading pictures

Can someone help me troubleshoot why my images are not displaying in the slider on my homepage? I have set up the slider using React Slideshow Image, but the images are not showing up for some reason. I am also wondering if anyone knows of any full-screen ...

Issues with table-cell rendering in Chrome

I have three different divisions that I would like to showcase as table cells: <div class="field"> <div class="row"> <label for="name">Subdomain</label> <input type="text" id="name" name="name"> &l ...

Support for dark mode in Svelte with Typescript and TailwindCSS is now available

I'm currently working on a Svelte3 project and I'm struggling to enable DarkMode support with TailwindCSS. According to the documentation, it should be working locally? The project is pretty standard at the moment, with Tailwind, Typescript, and ...

What is the functionality of the icon `<i>` in Twitter Bootstrap?

After adding an icon to a webpage, I noticed that it replaced the old, semi-deprecated <i> tag and instead used a customized image tag. It almost seems like <i ...> is just a simpler version of <img ...>. I'm curious about how this ...

Utilizing a Recycled jQuery UI Themeroller Overlay

I'm looking to optimize css-loading bandwidth by reusing the overlay from jQuery UI for a specific section of my page. However, I'm encountering an issue where the overlay only covers a semi-transparent blackout of the entire page instead of just ...

Combining arrays of objects sharing a common key yet varying in structure

Currently, I am facing a challenge while working on this problem using Typescript. It has been quite some time since I started working on it and I am hoping that the helpful community at StackOverflow could provide assistance :) The scenario involves two ...

Why is the CSS selector `:first-child:not(.ignore)` not working to exclude the `ignore` class from the selection?

Is there a way to utilize the first-child selector with the not(.ignore) selector to target every element that is the first child of its parent, except when that first child has the class ignore? I've experimented with :first-child:not(.ignore){...}, ...

Create a class for the grandparent element

Is there a way to dynamically add a class to a dropdown menu item when a specific child element is clicked? Here's the HTML structure I have: <ul id="FirstLevel"> <li><a href="#">FirstLevel</a></li> <li>< ...

Receiving contextual information from Microsoft Teams within an Angular application integrated as a tab

I am currently integrating an Angular website into a Microsoft Teams tab. In order to perform certain computations, I need to retrieve the Team ID. To achieve this, I have recently added npm install --save @microsoft/teams-js. Below is the code snippet th ...

Discover the process of dynamically importing JavaScript libraries, modules, and non-component elements within a Next.js

Lately, I have been utilizing Next.js and mastering its dynamic import feature for importing components with named exports. However, I recently encountered a particular npm package that functions only on the client-side (requires window) and has a substant ...

Tips for implementing a CSS override for a block element's relative date

I am looking to customize this source code by using a CSS override to ensure that the "lightning-relative-date-time" element is not utilized. I want to keep it displaying the timestamp information by default. Can you guide me on how to achieve this throu ...

What can be done to resolve unexpected website caching issues?

My current website is built using node.js for the backend and React.js for the frontend. I utilize Cloudflare with the following cache settings: Cache Level: Standard Browser Cache TTL: 4hrs Crawler Hints: On Always Online™: On Development Mode: Off In ...

Answer for background picture when reducing magnification

Currently, I am facing the challenge of converting a PSD template to HTML. Specifically, I need guidance on how to handle the background food images (highlighted in red in the image) when zooming out the browser. The total width is 1300px with a container ...

Using TypeScript with .env file variables: a step-by-step guide

I stored my secret jwt token in the .env file. JWT_SECRET="secretsecret" When I attempt to retrieve the value using process.env.JWT_SECRET, I encounter an error: Argument of type 'string | undefined' is not assignable to parameter of t ...

Encountering issues when passing a string as query parameters

How can I successfully pass a string value along with navigation from one component to another using query parameters? Component1: stringData = "Hello"; this.router.navigate(['component2'], { queryParams: stringData }); Component2: ...

Tips for managing several Material UI Slide Components at once

Utilizing Material UI's Slide component, I have encountered an issue with my code. Upon hovering over a card, I intend for an individual slide to appear. However, the current implementation causes both slides to be displayed when hovering over any of ...

Stop receiving updates from an observable once you navigate away from an Onsen UI page

I am facing an issue with my Angular 2+ app that utilizes Onsen UI. I have set up some components as pages and I am using the ons-navigator to switch between them. The problem arises when I subscribe to an observable in an ons-page and the user navigates ...

Converting a string to a number is not functioning as expected

I am facing a problem with an input shown below. The issue arises when trying to convert the budget numeric property into thousands separators (for example, 1,000). <ion-input [ngModel]="project.budget | thousandsSeparatorPipe" (ngModelChange)="projec ...

Is it possible to customize the formatting of the information displayed within a details tag when it is nested under a summary

Is there a way to format the details information so that it aligns underneath the summary tag? Currently, both lines of text are aligned to the left. <details> <summary> Summary 1 </summary> Details 1 </details> ...