I am working in React js and I already implemented the common component for the react-table
I am using react-table library for the table.
I need to add the custom class for some specific rows.
I already try to add couple of row props as well but i didn't get success in that.
Here is my table example
import React from 'react';
import { useTable, useExpanded } from 'react-table';
function Table({ className, colSpan, columns, data }) {
// Use the state and functions returned from useTable to build your UI
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
state: { expanded },
} = useTable(
{
className,
colSpan,
columns,
data,
},
useExpanded // Use the useExpanded plugin hook
);
// Render the UI for your table
return (
<table className={className} {...getTableProps()}>
<thead>
{headerGroups.map(headerGroup => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map(column => (
<th {...column.getHeaderProps()}>
{column.render('Header')}
</th>
))}
</tr>
))}
</thead>
<tbody {...getTableBodyProps()}>
{rows.map((row, i) => {
prepareRow(row);
return (
<tr {...row.getRowProps()}>
{row.cells.map(cell => {
return (
<td {...cell.getCellProps()}>
{cell.render('Cell')}
</td>
);
})}
</tr>
);
})}
{rows.length === 0 && (
<tr>
<td colSpan={colSpan}>No Record Found</td>
</tr>
)}
</tbody>
</table>
);
}