Comments (3)
For anyone searching for a fix to this, as I was...
I figured out a work-around to combine this library with react-table
without throwing an error. I basically copied react-super-responsive-table
's CSS, analyzed how it applies classNames to a table's individual elements once rendered in the browser, and applied that method to a table made with react-table
and Chakra UI instead of the react-super-responsive-table
components.
You can either copy the CSS from the react-super-responsive-table repo here into a CSS file of your own (as I did) or install the library and import only the CSS, like so:
import 'react-super-responsive-table/dist/SuperResponsiveTableStyle.css';
Here's the full code example:
(keep in mind that I'm using Next.js, CSS modules, and Chakra UI)
import { Table, Thead, Tbody, Tr, Th, Td, Box } from "@chakra-ui/react";
import { useTable } from "react-table";
import styles from "src/theme/css/tables.module.css";
import { chakra } from "@chakra-ui/react";
import { FaAngleDown, FaAngleUp } from "react-icons/fa";
const ChakraDownArrow = chakra(FaAngleDown);
const ChakraUpArrow = chakra(FaAngleUp);
import { useMemo } from "react";
const ResponsiveTableExample = () => {
// dummy data
const data = useMemo(
() => [
{ testData1: "hello", testData2: "world" },
{ testData1: "hello again", testData2: "old friend" },
],
[]
);
// dummy headers for the dummy data
const columns = useMemo(
() => [
{
Header: "Test1",
accessor: "testData1",
},
{
Header: "Test2",
accessor: "testData2",
},
],
[]
);
const {
getTableProps,
getTableBodyProps,
headerGroups,
page,
prepareRow,
} = useTable();
return (
// apply the appropriate class from the
// react-super-responsive-table CSS
<Table
{...getTableProps()}
className={styles.responsiveTable}
borderRadius="10px"
>
<Thead>
{headerGroups.map((headerGroup) => (
<Tr
{...headerGroup.getHeaderGroupProps()}
key={`table-row-${JSON.stringify(headerGroup)}`}
>
{headerGroup.headers.map((column, i) => (
<Th
{...column.getHeaderProps(column.getSortByToggleProps())}
key={`table-head-${column.Header}-${i}`}
>
{column.render("Header")}
<chakra.span pl="4%" key={`span-${column.Header}-${i}`}>
{column.isSorted ? (
column.isSortedDesc ? (
<ChakraDownArrow
aria-label="sorted descending"
key={`down-arrow-${column.Header}-${i}`}
/>
) : (
<ChakraUpArrow
aria-label="sorted ascending"
key={`up-arrow-${column.Header}-${i}`}
/>
)
) : null}
</chakra.span>
</Th>
))}
</Tr>
))}
</Thead>
<Tbody {...getTableBodyProps()}>
{page.map((row, i) => {
prepareRow(row);
return (
<Tr {...row.getRowProps()} key={`table-row-${row.id}-${i}`}>
{row.cells.map((cell, i) => {
return (
<Td
{...cell.getCellProps()}
key={`table-data-${cell.value}-${i}`}
// apply the appropriate class from the
// react-super-responsive-table CSS
className={styles.pivoted}
>
{/* map through headerGroups once again and only render
a header if it corresponds with the correct column */}
{headerGroups.map((headerGroup) => {
return (
<Box key={`${JSON.stringify(headerGroup)}-container`}>
{headerGroup.headers.map((column, i) => {
return cell.column.Header === column.Header ? (
<Box
key={`mobile-table-header-${column.Header}-${i}`}
// apply the appropriate class from the
// react-super-responsive-table CSS
className={styles.tdBefore}
>
{column.render("Header")}
</Box>
) : null;
})}
</Box>
);
})}
{cell.render("Cell")}
</Td>
);
})}
</Tr>
);
})}
</Tbody>
</Table>
);
};
export default ResponsiveTableExample;
from react-super-responsive-table.
Thanks for posting this @dayvista 💯
from react-super-responsive-table.
Hey @stephyswe! Thanks for creating this issue. It's a good idea. Is this an enhancement that you would like to contribute?
from react-super-responsive-table.
Related Issues (20)
- Action Required: Fix Renovate Configuration
- Headers disappearing when table pivots at breakpoint HOT 6
- Add css class for mobile view HOT 4
- THead not working with react-table hooks. HOT 4
- Prevent header column to repeate on every row HOT 3
- Cells without value dont create cell in target card, field value not on same row how field key HOT 4
- Error: Element type is invalid HOT 15
- Header in mobile view is not shown HOT 12
- Still having trouble with dynamic header HOT 2
- Request: Add support for React 18.x.x HOT 7
- How to customize CSS for the table and its elements?
- Change the width of headers in mobile view. HOT 6
- Styles do not get overriden
- Trying to use react beautiful dnd with superresponsive table but getting error while using ref inside <Tbody> and <Tr> HOT 2
- Can we use useTable hook with this table?
- replace defaultProps to default parameters HOT 6
- Header Height Responsiveness Issue HOT 1
- Place <td> below the <th> in mobile view instead of placing it on <th>'s right side. HOT 3
- Error : Global is not define. HOT 1
- React not recognising prop on a DOM element;
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-super-responsive-table.