Snippets Collections
/* spacing */

table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  border: 3px solid purple;
}

thead th:nth-child(1) {
  width: 30%;
}

thead th:nth-child(2) {
  width: 20%;
}

thead th:nth-child(3) {
  width: 15%;
}

thead th:nth-child(4) {
  width: 35%;
}

th, td {
  padding: 20px;
}
<table>
  <caption>Caption describing what the table is about</caption>
  <thead>
    <tr>
      <th scope="col">Column 1 Heading </th>
      <th scope="col">Column 2 Heading</th>
      <th scope="col">Column 3 Heading</th>
      <th scope="col">Column 4 Heading</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Row 1 Heading</th>
      <td>Row 1 - Colummn 1 data</td>
      <td>Row 1-Column 2 Data</td>
      <td>Row 1 - Column 3 Data</td>
    </tr>
    <tr>
      <th scope="row">Row 2 Heading</th>
      <td>R2-C1 Data</td>
      <td>R2-C2 Data</td>
      <td>R2-C3 Data</td>
    </tr>

    <!-- several other great bands -->

    <tr>
      <th scope="row">Row 3 Heading</th>
      <td>R3-C1 Data</td>
      <td>R3-C2 Data</td>
      <td>R3-C3 Data</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <th scope="row" colspan="2">Bottom Rows</th>
      <td colspan="2">77</td>
    </tr>
  </tfoot>
</table>
Table ... / nocellmerge misstext=' ';
import React from "react";
import PropTypes from "prop-types";

const Header = ({ title }) => {
  return (
    <header className="header">
      <h1>{title}</h1>
    </header>
  );
};

Header.propTypes = {
  title: PropTypes.string.isRequired,
};

export default Header;


///// ----- USING IT -------
import Header from "./components/Header";
<Header title="New Pixar Movies" />
import React from "react";
import PropTypes from "prop-types";

const Table = ({ tableData, headingColumns, title, breakOn = "medium", onItemClick, onHeadingClick, headingColumnFields }) => {
  let tableClass = "table-container__table";

  if (breakOn === "small") {
    tableClass += " table-container__table--break-sm";
  } else if (breakOn === "medium") {
    tableClass += " table-container__table--break-md";
  } else if (breakOn === "large") {
    tableClass += " table-container__table--break-lg";
  }

  const data = tableData.map((row, index) => {
    let rowData = [];
    let i = 0;

    for (const key in row) {
      rowData.push({
        key: headingColumns[i],
        val: row[key],
      });
      i++;
    }

    return (
      <tr key={index} onClick={()=>onItemClick(index)}>
        {rowData.map((data, index) => (
          <td key={index} data-heading={data.key}>
            {data.val}
          </td>
        ))}
      </tr>
    );
  });

  return (
    <div className="table-container">
      <div className="table-container__title">
        <h2>{title}</h2>
      </div>
      <table className={tableClass}>
        <thead>
          <tr>
            {headingColumns.map((col, index) => (
              <th key={index}  onClick={() => onHeadingClick(headingColumnFields[index])}>{col}</th>
            ))}
          </tr>
        </thead>
        <tbody>{data}</tbody>
      </table>
    </div>
  );
};

Table.propTypes = {
  tableData: PropTypes.arrayOf(PropTypes.object).isRequired,
  headingColumns: PropTypes.arrayOf(PropTypes.string).isRequired,
  title: PropTypes.string.isRequired,
  breakOn: PropTypes.oneOf(["small", "medium", "large"]),
  onItemClick: PropTypes.func.isRequired,
  onHeadingClick: PropTypes.func.isRequired,
  headingColumnFields: PropTypes.arrayOf(PropTypes.string).isRequired
};

export default Table;



// ------ USING THE TABLE -------
import Table from "./components/Table";
        {data ? (
          <Table
            tableData={data.results.sort(sortMovies).map((movie) => {
              return [
                data.title,
                new Date(data.release_date).toLocaleDateString(
                  undefined,
                  options
                ),
              ];
            })}
            headingColumns={["Title", "Release Date"]}
            title="Pixar Movies"
            breakOn="small"
            onItemClick={handleClick}
            onHeadingClick={handleSort}
            headingColumnFields={["title", "release_date"]}
          />
        ) : null}
star

Sat Jul 16 2022 08:06:52 GMT+0000 (UTC) https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Styling_tables

#tablestylecss #csstablestyle #table
star

Sat Jul 16 2022 08:04:05 GMT+0000 (UTC) https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Styling_tables

#table #tablelayout #typical_html_table
star

Wed May 04 2022 23:27:04 GMT+0000 (UTC)

#table #proctabulate
star

Thu Jul 29 2021 20:28:06 GMT+0000 (UTC)

#javascript #react #table

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension