Table field plugin for Kirby CMS

Kirby Table Field

The table field streamlines the management of structured data in tables, offering a user-friendly interface that simplifies data entry and enhances content creation by making tabular information effortlessly manageable.

Installation

Composer

composer require bogdancondorachi/kirby-table-field

Git Submodule

git submodule add https://github.com/bogdancondorachi/kirby-table-field.git site/plugins/table-field

Manual

Download and extract the folder to /site/plugins/kirby-table-field

Usage

Add the field to your blueprint:

fields:
  table:
    label: table
    type: table
    #optional (see props below)

Field Properties:

Name Type Default Description
index Number, Boolean 1 Specifies the starting index. If set to false, it removes the index column; in this case, sortable also needs to be set to false
sortable Boolean true Toggles drag & drop sorting
minColumns Number 2 Sets the minimum required columns in the table
minColumns Number 5 Sets the maximum allowed columns in the table

Use the field in your template:

<?php $table = $page->table()->toTable(); ?>
<?php if($table != null): ?>
  <table>
    <thead>
      <tr>
        <?php foreach ($table['headers'] as $header): ?>
          <th><?= $header ?></th>
        <?php endforeach ?>
      </tr>
    </thead>
    <tbody>
      <?php foreach ($table['rows'] as $row): ?>
        <tr>
          <?php foreach ($row as $cell): ?>
            <td><?= $cell ?></td>
          <?php endforeach ?>
        </tr>
      <?php endforeach ?>
    </tbody>
  </table>
<?php endif ?>

Credits

License

MIT License Copyright © 2024 Bogdan Condorachi

GitHub

View Github