Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

nblum/silverstripe-table-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silverstripe-table-field

Allows to edit tables in wysiwyg style. Saves the result in json.

screenshot

Installation

composer require nblum/silverstripe-table-field

Usage

In model

private static $db = [
    'Table' => 'Varchar',
];

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    $fields->addFieldsToTab('Root.Main', [
        TableField::create('Table', 'Table')
    ]);

    return $fields;
}

public function Table()
{
    return new ArrayList(array_reduce(json_decode($this->dbObject('Table')->value), function ($carry, $row) {
        $carry = is_array($carry) ? $carry : [];
        return array_merge($carry, [['row' => new ArrayList(array_reduce($row, function($carry, $column) {
            $carry = is_array($carry) ? $carry : [];
            return array_merge($carry, [['column' => $column]]);
        }))]]);
    }));
}

In template

<table>
    <% loop $Table %>
        <tr>
            <% loop $row %>
                <%-- Using .RAW lets us but <b> tags in the table fields --%>
                <td>$column.RAW</td>
            <% end_loop %>
        </tr>
    <% end_loop %>
</table>

Configuration

There are no configuration options

Todos

  • add config options for max rows and cols

About

Allows to edit tables in wysiwyg style

Resources

License

Stars

Watchers

Forks

Packages

No packages published