Tips on eliminating borders in react-table components

Within my React.js component, I have implemented a table using react-table along with some material-ui components displayed alongside the table:

import React from 'react'
import { useTable, useGlobalFilter, usePagination } from 'react-table'
import { makeGetRequest } from "../state/actions";
import PropTypes from "prop-types";
import { connect } from "react-redux";
//Material UI imports
import { styled } from '@mui/material/styles';
import Paper from '@mui/material/Paper';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import ButtonGroup from '@mui/material/ButtonGroup';
import TextField from '@mui/material/TextField';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';

const Item = styled(Paper)(({ theme }) => ({
  ...theme.typography.body2,
  padding: theme.spacing(1),
  textAlign: 'center',
  color: theme.palette.text.secondary,

}));

export const GlobalFilter = ({ filter, setFilter }) => {
  return (
    <span>
      <TextField 
        id="outlined-basic" 
        label="Search" 
        variant="outlined"
        size="small"
        value={filter || ''}
        onChange={e => setFilter(e.target.value)} />
    </span>
  )
}

function Table({ columns, data }) {

  const handleEntriesChange = (event) => {
    setPageSize(event.target.value);
  };
    
  // Use the state and functions returned from useTable to build your UI
  const {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    rows,
    prepareRow,
    page,
    pageOptions,
    state: { pageIndex, pageSize },
    previousPage,
    nextPage,
    canPreviousPage,
    canNextPage,
    setPageSize,
    state,
    setGlobalFilter,
    } = useTable(
        { columns, data, initialState: { pageSize: 10 }},
        useGlobalFilter, usePagination,
        )

  const { globalFilter } = state

  // Render the UI for your table
  return (
      <>
      <Box sx={{ minWidth: 120 }}>
          <InputLabel id="entries-label">Show Entries</InputLabel>
          <Select
            labelId="entries-label"
            id="entries-label"
            value={pageSize}
            label="Entries"
            onChange={handleEntriesChange}
          >
            <MenuItem value={10}>10</MenuItem>
            <MenuItem value={20}>20</MenuItem>
            <MenuItem value={50}>50</MenuItem>
            <MenuItem value={100}>100</MenuItem>
          </Select>
      </Box>
        <GlobalFilter filter={globalFilter} setFilter={setGlobalFilter}/>
      <table {...getTableProps()}>
          <thead>
          {headerGroups.map(headerGroup => (
              <tr {...headerGroup.getHeaderGroupProps()}>
              {headerGroup.headers.map(column => (
                  <th {...column.getHeaderProps({
                    style: {  minWidth: column.minWidth, width: column.width },
                    })}>
                    {column.render('Header')}
                  </th>
              ))}
              </tr>
          ))}
          </thead>
          <tbody {...getTableBodyProps()}>
          {page.map(row => {
              prepareRow(row)
              return (
              <tr {...row.getRowProps()}>
                  {row.cells.map(cell => {
                  return  <td  {...cell.getCellProps()}>
                            {cell.column.Header=='LOCKER' ?
                              cell.render('Cell')
                             : 
                              cell.render('Cell')} 
                          </td>
                  })}
              </tr>
              )
          })}
          </tbody>
      </table>
        <ButtonGroup aria-label="button group">
          <Button variant="outlined" onClick={() => previousPage()} disabled={!canPreviousPage}>Previous</Button>
          <Button variant="contained" >{pageIndex + 1}</Button>
          <Button variant="outlined" onClick={() => nextPage()} disabled={!canNextPage}>Next</Button>
        </ButtonGroup>
      </>
  )
}

function LockerListTable(props) {

  const columns = React.useMemo(
      () => [
        {
          Header: '#',
          accessor: 'id',
          width: 200,
          minWidth: 20
        },
        {
          Header: 'LOCKER',
          accessor: 'locker_name',
          width: 1000,
          minWidth: 100
        },
        {
          Header: 'LOCATION',
          accessor: 'location',
          width: 1000,
          minWidth: 100
        },
        ],[]
  )
  
    const data = React.useMemo(() => props.locker_list_data, [props])
  
  return (
      <Table columns={columns} data={data} />
  )
}

LockerListTable.propTypes = {
  locker_list_data: PropTypes.array.isRequired,
};

const mapStateToProps = (state, ownProps) => {
  return { locker_list_data: state.handleAPI.locker_list_data };
};

const mapDispatchToProps = (dispatch) => {
  return {
    makeGetRequest: (url, componentName) => dispatch(makeGetRequest(url, componentName)),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(LockerListTable);

I've also applied custom CSS styling to the table, where the border has been set to 'border:none':

.table{
    font-size: 13px;
    text-align: center;
    width: 100%;
    margin: auto;
}

table.table-bordered_low_stock > thead > tr > th{
    border: none;
    padding-top: 3px;
    padding-bottom: 3px;
}

tbody tr:nth-child(odd){
    background: #e0e0e0;
}

tbody tr:nth-child(even){
    background: #bdbdbd;
}

th {
  background-color: #343A40 ;
  color: white;
  
}

Here is an image preview of the table: https://i.stack.imgur.com/8fiYm.png

I'm currently facing issues removing the white border lines between the rows and columns in the table. I've attempted various solutions from stackoverflow without success so far. Any advice would be greatly appreciated!

Answer №1

Include the code snippet below in your table:

.table {
  border-collapse: collapse;
}

Answer №2

If you want to remove the border from a table, you can achieve this by using the border-collapse property in your CSS code. Here's an example:

.table{
    font-size: 13px;
    text-align: center;
    width: 100%;
    margin: auto;
    border-collapse: collapse;
}

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

Failure to specify the variable type can lead to the creation of automatic global variables

Recently, I stumbled upon this http://www.w3schools.com/js/js_scope.asp page which introduced me to the concept of "Automatic Global variables". Here is an example of how it works: // You can use carName variable here function myFunction() { carName ...

Connecting a href link to a TAB

Check out this useful CODE example I am using. I have a webpage with links that have href attributes. Now, I want to link these pages to another page and have them automatically open a specific tab when clicked. Is this possible? Here are the links on th ...

Instructions for creating a background within a container and positioning text in the center of the image utilizing HTML and CSS

I am currently learning HTML, CSS, and JavaScript. I am in the process of building my very first website, but I have encountered a problem. I am struggling to change the background color within the container beneath the images to a specific color (#82b5cf) ...

Interactive back button for seamless navigation back to the originating modal

This website is built on Bootstrap 4. As I develop this site, there are a total of 17 different modals. Specific words in each modal are linked to other modals for additional information. However, getting back to the previous modal requires closing the ...

CSS: Trouble with elements positioning

I am attempting to position two boxes on top of each other at the bottom of a different div. Here is the code I have: <div style = "height:400px;width:400px;border:1px solid #000;"> <div style = "position:relative;height:100px;width:100px;bor ...

Utilize $.get AJAX to extract data from a multidimensional JSON array

Struggling to make two functions work on my form that uses AJAX and jQuery to look up an array. One function is functional while the other seems to be causing confusion with over-analysis and extensive troubleshooting. Any insights into what may be missing ...

Adding a gap between the Bootstrap navbar and jumbotron for better spacing

Upon examining the Bootstrap example provided at: http://getbootstrap.com/examples/navbar/ I noticed there is a gap between the jumbotron and the navbar. After delving into the example's CSS, I found that disabling this rule (twice): .navbar { ...

Creating files using the constructor in Internet Explorer and Safari

Unfortunately, the File() constructor is not supported in IE and Safari. You can check on CanIUse for more information. I'm wondering if there's a workaround for this limitation in Angular/JavaScript? var file = new File(byteArrays, tempfilenam ...

Unusual occurrence while creating a unique identifier for a React component

I am working on creating a unique identification number for each React component, which will be assigned to the component upon mounting. Here is the approach I am taking: The callOnce function is used to ensure that a specific function is only executed on ...

jQuery mobile not recognizing the ID we specified

I am in the process of developing an audio application. My goal is to change the id of the Play button dynamically to "paused" when it is clicked. However, despite my efforts, clicking on the "paused" button does not pause the audio as intended. $(&ap ...

Show a div pulsating while simultaneously animating another div

After coming across this query on Stack Overflow about adding a class without jQuery if hovering over another class I encountered an issue with a div element that displays upon hovering over a span, which was functioning correctly. However, I also have a ...

Unable to send headers to the client in expressjs as they have already been set

After successfully logging in, I am trying to redirect to another page but keep encountering the error message "Cannot set headers after they are sent to the client". I understand that I need to place the res.redirect method somewhere else in my code, bu ...

Setting up a connection to MongoDB on a local network using express and mongoose

As I set up a server with express and mongoose, my goal is to make it accessible on other devices within my local network. To achieve this, I configured the bind_ip variable to 0.0.0.0 in the Mongodb configuration file. const connection = mongoose .co ...

``Trouble with React Dropdown menu option selection"

I am encountering challenges with implementing a dropdown menu list for my react app. The issue at hand is that I have an API where one of the keys (key3) has values separated by commas that I wish to display in my dropdown list. The structure of the API ...

Latest output is fetched by jQuery from the load() method

I'm encountering an issue with the code present in index.html: $(document).ready(function() { $('#generate').click(function() { //$("#results").empty(); $("#results").html(""); $("#results").load("generate.php"); }); }); In addition ...

Utilizing the React Native Expo image picker for SDK 46 with asset ID type functionality

When using expo-image-picker, the assetId type can be string, null, or undefined. This implies that the ID may not always be available, such as when the user has limited permissions to access the media library on iOS or when selecting a photo directly from ...

Error message encountered in React: "Uncaught TypeError: Unable to access property of undefined"

Having some trouble as a React beginner. The following code snippet is causing an error that says: "Uncaught TypeError: Cannot read property 'creationDate' of undefined". When I move the code from populateTableRows and creationDate function ...

Google Chart Fails to Display

I am encountering an issue while attempting to integrate a Google chart into my project. The page fails to load, rendering a blank screen. Initially, the page displays correctly for a brief moment after loading and then suddenly turns blank, becoming unres ...

Inspecting Facebook links

Currently working on a website and interested in incorporating a feature similar to what Facebook has. I'm referring to the link inspector, but I'm not entirely sure if that's its official name. Allow me to provide an example to clarify my r ...

What is the process for encrypting a string in JavaScript?

Is there a simple way to hash a string in JavaScript without having to create the hashing algorithm myself? Are there any reliable npm packages or built-in functions available for this task? If so, how can I utilize them to hash a string? For instance, if ...