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

The issue of JQuery recursion not properly focusing on a textbox

Can anyone help with a jquery focus issue I'm experiencing? My goal is to address the placeholder problem in IE by focusing on an element and then blurring it to display the placeholder. This functionality is being used in a modal form. Initially, e ...

The integration of cypress-cucumber-preprocessor with multiple testing frameworks appears to be experiencing compatibility issues

I am trying to set up a connection between Cypress and Cucumber, and I came across this plugin: https://www.npmjs.com/package/cypress-cucumber-preprocessor However, I am having trouble with my implementation as it seems to be missing. I have also added th ...

What could be the reason behind my table appearing all crammed up in a single

My table is appearing in a single cell, and I can't figure out what's wrong. Can someone please take a look and let me know where I messed up? <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" cont ...

Dynamically shift the table footer to the bottom of a scrolling div by utilizing jQuery

I'm facing a challenge where I need to relocate each th tag from the footer row of a table to the bottom of a scrolling div. You can check out the scenario on this link. Currently, I am able to achieve this by hardcoding it like so: $('.sticky- ...

Issue with Cross-Origin Request in ReactJS and Java: Preflight request failing access control validation

While working on fetching data from a Java backend using axios, I encountered a CORS issue leading to failure (Refer to the attached screenshot). Interestingly, I found that if I remove the AuthToken part in my axios file, it works perfectly with a status ...

"Sweet syntax" for assigning object property if the value is true

In the project I'm working on, I find myself dealing with a lot of parsing and validating tasks. This often results in 5-10+ lines of code like if(value) object.value = value. I considered using object.value = value || (your favorite falsy value) app ...

Despite the correct value being displayed in the console.log, the Textfield is not responding to the Reducer

I am currently working on a project to create a tool that can iterate through the pupils of a school class. In order to achieve this, I have implemented a text field in a react component that displays a value: <input className="form-control" onChange={ ...

What is the process of relocating JSON and JS code from within an HTML file to external files?

My goal is to separate JSON and JavaScript code from the HTML file by moving them into external files. The examples shown below were part of a test I conducted to verify that the data was being successfully imported. As I begin to include real data, the J ...

Transitioning from a traditional CURL method to utilizing AJAX and XMLHttp

I'm currently facing a challenge converting the curl code from an API named TextRazor to AJAX XMLHttp due to limitations on the platform I am working with. Despite trying various solutions shared by the community, I have been unsuccessful in retrievin ...

I am eager to re-execute the query by simply clicking on buttons, however, it seems to not be functioning properly

export const useCustomLogin = (loginType) => { return useQuery({ queryKey: ['custom-login', loginType], // 'custom-login' is a simple function that uses axios get method queryFn: async () => await customLogin(loginTy ...

dynamically import a variety of components in vue.js and nuxt depending on certain conditions

Is there a way to implement dynamic imports for all 3 components in this scenario? Each component has different props, so using the switch option in the computed method is not feasible. I have come across solutions for using a single component dynamically ...

Why does my Div seem to be ignoring the height inherited from the html or body elements?

Is there a way to make the landing-wrapper div expand to fill 100% of the screen on a landing page? Many suggestions advise setting the html/body height to 100%. I've already tried that, but it doesn't seem to be working. I'm using React and ...

JavaScript: Append an ellipsis to strings longer than 50 characters

Can the ternary operator be utilized to append '...' if a string surpasses 50 characters? I attempted this approach, however it did not work as expected. {post.title.substring(0, 50) + post.title.length > 50 ? '...&ap ...

Tips for resolving the UNABLE_TO_GET_ISSUER_CERT_LOCALLY issue while attempting to install Sentry using npm or curl

https://i.stack.imgur.com/G8hfZ.png curl -sL -k https://sentry.io/get-cli/ | bash Even though I've specified not to verify the certificate with -k, I'm still facing issues trying to install it. The script is supposed to automatically install sen ...

Tips for accessing key-value arrays in PHP sent via Ajax POST requestsHow to effectively retrieve key-value pairs

Is there a way to access a key and value array passed through an ajax call to a PHP function on the PHP side using the $_POST method? var eImages = [{ ProductID: ProductID, Image: image1Name, ImagePath: image1Path }, { ProductID: Produc ...

Hindering advancement: Bootstrap Form Wizard causing roadblocks

I am currently facing an issue with my form wizard setup. I want to prevent the user from advancing to the next step when the success key in my json is set to false. It seems like the project is utilizing the bootstrap wizard plugin. You can find more in ...

Converting a json array into a map with the help of Underscore.js

My challenge involves parsing a JSON array into a map object, with the key being the state and the value being an array of objects that share the same state. An example JSON data set is provided below: { "totalRec": 10, "content": [ { "name" ...

Efficient method to retrieve my app's version in a React Native environment

I have a React Native app that I created using the command react-native init. I want to define a global constant for my APP_VERSION so that I can access it in the Authentication/Login screen. Currently, the only place I see this variable is in my package. ...

`What can be done if ng-if is not responding?`

I'm facing an issue where I want to display a link <a href> only when a certain condition is met, but the link doesn't show up as expected. I have already attempted to experiment with changing the position of the code (inside or outside of ...

Leveraging an external global variable file that is not incorporated into the bundle

I have a JavaScript file dedicated to internationalization. I am looking for a way to provide this file to clients for them to edit without requiring me to rebuild the entire project. Currently, I store this file in the static folder so it is included in ...