Skip to content

Kirby 2. This custom field for Kirby CMS displays Kirby's Structure Field as a DataTable inside the panel (Kirby's backend)

License

Notifications You must be signed in to change notification settings

fendinger/kirby-datatable-field

Repository files navigation

Kirby 2 DataTables Field

This custom field for Kirby CMS displays Kirby's Structure Field as a DataTable inside the panel (Kirby's backend).

DataTables from DataTable.

CSS from Jon Gacnik.

Kirby DataTables Field Screenshot

Blueprint example

fields:
...
  datatable:
    label: DataTable
    type: datatable
    fields:
      text:
        label: text
        type: textarea
      picture:
        label: Background Image
        type: image
      headline:
        label: Headline Text
        type: text

Filter Data

A custom filter can be applied to the data before it is put out as a json response. This is perfect if you need to modify some of the data for presentation, change columns, etc.

Create a simple plugin site/plugins/mydatafilters/mydatafilters.php:

<?php

class MyDataFilters {
  static function myfilterfunc($data) {
    // filter data here
    foreach ($data as $entry) {
      if ($data->{$entry->{'id'}}->{'text'} == '') {
        $data->{$entry->{'id'}}->{'text'} = '- no text -';
      }
    }
    return $data;
  }
}

Update field definition:

datatable:
  label: DataTable
  type: datatable
  filter: MyDataFilters::myfilterfunc
  fields:
    text:
      label: text
      type: textarea
      ...

Template Usage

You use it similar to Kirby's Structure Field.

Setup

git clone https://github.com/fendinger/kirby-datatable.git site/fields/datatable From the root of your kirby install.

Alternatively you can download the zip file, unzip it's contents into site/fields/datatable.

Known Issues

Some issues related to the structure field of Kirby Panel do also affect the datatable field.

Not all DataTables functions are implemented already. But it's a good starting point.

About

Kirby 2. This custom field for Kirby CMS displays Kirby's Structure Field as a DataTable inside the panel (Kirby's backend)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published