Skip to content

Table with editable cells in WordPress

A table whose values are edited in place with mouse or keyboard: Enter saves, Escape cancels, input is checked and the change announced.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

pattern.html
<!-- wp:html -->
<section class="tcm" data-tcm aria-labelledby="tcm-titre">
        <p class="tcm-eyebrow">Boulangerie Lefèvre · fournée de demain</p>
        <h2 class="tcm-title" id="tcm-titre">Production du samedi</h2>
        <p class="tcm-lead" id="tcm-aide">Touchez une valeur pour la modifier. Entrée valide, Échap annule.</p>
        <p class="tcm-sr" role="status" data-tcm-status></p>
        <div class="tcm-scroll">
          <table class="tcm-table" aria-describedby="tcm-aide">
            <caption class="tcm-sr">Quantités et prix de la fournée, modifiables</caption>
            <thead>
              <tr>
                <th class="tcm-head" scope="col">Produit</th>
script.js
(() => {
  if (!document.querySelector(".tcm")) return;
  document.querySelectorAll("[data-tcm]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const status = root.querySelector("[data-tcm-status]");
    const error = root.querySelector("[data-tcm-error]");

    root.querySelectorAll("[data-tcm-cell]").forEach((cell) => {
      const show = cell.querySelector("[data-tcm-show]");
      const input = cell.querySelector("[data-tcm-input]");
      const name = cell.parentElement.querySelector("th").textContent.trim();
      const label = input.getAttribute("aria-label").split(",")[0];
style.css
:root {
  --tcm-card: #ffffff;
  --tcm-text: #221c16;
  --tcm-muted: #5a4f43;
  --tcm-line: #e3dacd;
  --tcm-hover: #f6efe4;
  --tcm-accent: #9a3412;
  --tcm-error: #b91c1c;
  --demo-tableau-cellules-modifiables-bg: #f0e9de;
  --demo-tableau-cellules-modifiables-text: #221c16;
}
tableau-cellules-modifiables.php
<?php
/**
 * Plugin Name: Forge, Tableau à cellules modifiables
 * Description: Un tableau dont les valeurs se modifient sur place, à la souris ou au clavier : Entrée valide, Échap annule, la saisie est contrôlée et la modification annoncée. Ajoute la composition « Tableau à cellules modifiables » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-tableau-cellules-modifiables
 *

Free component: copy it freely, including for commercial projects.

Data tables components in WordPress
  • A documentation table showing where a kit or component has been tested (static HTML, WordPress, Elementor, Webflow, v0…), with status, last test date and a remark, filterable by status.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A table of the towns and postcodes a tradesperson covers, with response time and travel fee, filtered by search and by zone.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A timetable table sorted by column and filtered with level and free-place chips, whose rows each become a card on phones.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A filterable table whose visible rows export in one click to a CSV file that opens cleanly in Excel or LibreOffice.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A price table by service: one package to pick, options to tick, and the total with the estimated time recalculated on every click.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A product spec sheet as two-column tables in native collapsible sections, with a button to open or close them all.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component