Creating a unique design for a row within a table using React

Struggling with a simple issue that I can't seem to figure out due to my lack of styling skills... How can I adjust the default height of table rows using a css-in-js approach?

First attempt involved using material-ui's Table and TableRow:

const StyledTableRow = withStyles((theme: Theme) =>
    createStyles({
        root: {
            height: '10px', // but this didn't work
        },
    }),
)(TableRow);

Second attempt was with mui-datatables' MUIDataTable:

const getMuiTheme = (globalTheme: Theme) =>
        createMuiTheme({
            overrides: {
                //MUIDataTable {}, // Saw this as a solution somewhere, but couldn't get it to work
                MuiTableRow: {
                    root: {
                        height: '10px' // also unsuccessful
                    },
                }
             }
          });

return (
        <MuiThemeProvider theme={getMuiTheme(globalTheme)}>
            <MUIDataTable
                title={props.title}
                data={props.data}
                columns={props.columns}
                options={options}
            />
        </MuiThemeProvider>
    );

If anyone has insights on either of these approaches, I would truly appreciate it :)

Answer №1

One way to customize your TableRow in materialui is to use classNames as shown below:

const customStyles = makeStyles((theme)=>({
  tableRow: {
    height: 50,
  },
}));

const customClasses = customStyles()

    

<TableRow className={customClasses.tableRow}>
  ...
</TableRow>

Answer №2

The height of the TableRow in a table is determined by two main factors. Firstly, the actual height of the TableRow itself needs to be considered. Secondly, the padding and height of the TableCell within the row also play a role. The default padding of the TableCell can impact the overall height of the TableRow, as it may prevent the height from reducing beyond a certain point.

const StyledTableRow = withStyles((theme) =>createStyles({
  root:{
    height:'20px',
  }
})
)(TableRow);
const StyledTablCell = withStyles((theme) =>createStyles({
  root:{
    backgroundColor:'yellow',
    padding:'0'
  }
})
)(TableCell);

To see a working demo, click on the following link:
https://codesandbox.io/s/blazing-currying-odo0c?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

How to retrieve an element's background color in hexadecimal using jQuery

I am attempting to retrieve the background colors of elements. $(document).ready(function(){ $.each('.log-widget',function(){ console.log($(this).css('backgroundColor')); //$(this).css({'box-shadow':'1px 1px ...

Get rid of the TypeScript error in the specified function

I am currently working on implementing a "Clear" button for a select element that will reset the value to its default state. Here is a snippet of my code: const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => { onChange( ...

Troubleshooting Issue: Unable to Display Dropdown Menu with Bootstrap 5 and ReactJS

Attempting to showcase a simple NavBar from the bootstrap documentation (https://getbootstrap.com/docs/5.0/components/navbar/) in React. I installed Bootstrap using npm I bootstrap. Here is the structure of my App: https://i.sstatic.net/h41mr.png Below ...

Changing the div background color based on the status of the `.play()` function

I need assistance with changing the background color of a div based on whether an audio file is playing or not. $('.uprow2').on('click', function() { $('#karma')[0].play(); }); .uprow2 { width: 680px; height: 60px; ...

Bootstrap 4 Vertical Timeline Layout Showing Uneven Columns Due to Large Margins

I'm currently working on my very first website and trying to implement a vertical timeline using Bootstrap 4. My goal is to have the timeline bar situated between two columns. However, I'm encountering an issue where I can't align text in th ...

What is the best way to dynamically adjust the width and height of an image when passed with the Materal-UI Modal component?

For reference, here's a code sandbox example related to this issue. The main objectives are: 1. Click the open modal button to reveal the modal. 2. The opened modal should display the complete image without any margins or paddings. To achieve this ...

Tips for customizing the scrollbar in React Virtuoso

To maintain a consistent style across different devices, I am planning to incorporate the use of "react-simple-scrollbar". It seems to work well with a traditional overflow div but encounters issues with Virtuoso. How can I address this problem? Below is ...

Conceal sub-menu icons within the jQuery User Interface Menu Widget

Is there a way to hide the submenu icon for the jQuery UI menu widget? The default value is set to ui-icon-carat-1-e. $(document).ready(function(){ $(function() { $( "#menu" ).menu({ icons: { submenu: false ...

Using CSS3 to target the final <li> element within the main list in a nested <ul> structure

I have a complex list structure: <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li> <ul> <li>Nested Item</li> <li>Nested Item</li> <li>L ...

The content is displayed below the navigation bar rather than beside it

I'm having an issue with the layout of my webpage. The new content I add appears below the navbar on the left side of the page instead of beside it. Can someone help me troubleshoot this problem? Below, you'll find the relevant HTML and CSS code ...

Building amazing 3D text with react-three/fiber

Trying to generate 3D text using Threejs and react-three/fiber has been a challenge for me. I successfully loaded the font using the FontLoader like so: const font = new FontLoader().parse('/Microsoft Tai Le_Regular.json'); However, when attempt ...

Design of web pages, Cascading Style Sheets

I want to add another table next to my dataGrid, floating to the left of it. Like this representation in the main div: | | | | A | B | | | | Here, A represents the current dataGrid containing all user information, and B will be the ...

Troubleshooting Safari compatibility with CSS transitions: a first attempt

Greetings everyone, I am a complete beginner here so please bear with me. After looking at some examples, I have managed to create a start/stop slowdown feature. Here is the JSFiddle link for reference .small-wheel, .big-wheel{ transition: all 2s ease ...

Expand a div without causing any displacement to surrounding elements

If you have 4 colored divs (red, yellow, green, blue), with 2 per row, and need to expand the second (yellow) without creating a gap under the red, check out this solution. The blue will be positioned underneath the expanded yellow. For a live example, vi ...

Retrieve information from a related table using a foreign key in Sequelize and Postgres

Currently, I am in the process of developing a NextJs NodeJs Express application that utilizes Postrges as its database system. In addition, I have set up two servers and incorporated axios to facilitate get and post requests to interact with my API endpoi ...

Exploring the possibilities of incorporating animations into each state transition with framer motion

Initially, I believed that each time Framer Motion would re-do my animation because the initial state is set to hide and the animate state is set to show. However, it turns out this is not true. Is there a way to make the animation replay on every state c ...

The mobile header appears without any background shading

Hey there, I'm encountering a puzzling issue: I have a header with a gradient background that displays perfectly on desktop. However, when I preview it on Chrome mobile emulator, it looks fine. But when I test it on an actual tablet or mobile device, ...

Uncovering the Reasons Behind Multiple Accesses to a ReactJS Page

The code snippet provided shows an issue with accessing the /profile page. Upon accessing the page, there are 6 POST requests sent to the backend. However, after implementing the useEffect hook, while the page is still accessed 6 times, now only 2 POST req ...

How can I handle CSV files in a NextJS application on my local machine?

Is it possible to manipulate a CSV file using a locally deployed NextJS app? I plan on running the server on my system and utilizing the frontend to process data within the CSV. Once completed, I aim to save the updated data back to the original file. Opti ...

Is it necessary for all elements of a web application to exist as React components?

It's been more than 2 years since I last worked with React, and revisiting my old code has left me feeling a bit confused. If I were to create an Instagram clone, would it be best to use HTML templates and inject JavaScript like this: <div id="rea ...