/handsontable-php

PHP wrapper for JavaScript Handsontable library

Primary LanguagePHPGNU Affero General Public License v3.0AGPL-3.0

handsontable-php

handsontable-php is a PHP library that works as a wrapper for the Handsontable js library (https://handsontable.com/) and it was built with flexibility and maintainability in mind. It is a simple port of the JavaScript library to PHP, it was designed in a way to evolve in order that developer only needs to learn one API. This software is under AGPL-3.0 LICENCE.

Setup

The recommended way to install handsontable-php is through Composer. Just create a composer.json file and run the php composer.phar install command to install it:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/openSILEX/handsontable-php"
        }
    ],
    "require": {
        "openSILEX/handsontable-php": "dev-master"
    }
}

Usage

Configure examples :

After installing handsontable-php (through "Composer"), put the examples directory in a web server accessible path. Set the right vendor path in examples/config/configLibrairy.php

After you will be able to use example, try this :

(http://localhost/examples/array.php)

Simple case (array.php)

require_once './config/configLibrairy.php';

use openSILEX\handsontablePHP\adapter\HandsontableSimple;

/**
 * An example to load a PHP array in Handsontable
 */

$hd = new HandsontableSimple();
$data = [
    ['', 'Tesla', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
    ['2017', 10, 11, 12, 13, 15, 16],
    ['2018', 10, 11, 12, 13, 15, 16],
    ['2019', 10, 11, 12, 13, 15, 16],
    ['2020', 10, 11, 12, 13, 15, 16],
    ['2021', 10, 11, 12, 13, 15, 16]
];
$hd->setData($data);

?>
<html>
    <head>
        <?= $hd->loadJSLibraries(true); ?>
        <?= $hd->loadCSSLibraries(); ?>
    </head>
    <br>
    <h3><b>Simple array</b></h3>
    <br>
    <?= $hd->render() ?>
</html>
?>

Ajax case (autocompleteAjax.php)

<?php
require_once './config/configLibrairy.php';

use openSILEX\handsontablePHP\adapter\HandsontableSimple;
use openSILEX\handsontablePHP\classes\ColumnConfig;
use openSILEX\handsontablePHP\classes\AjaxSourceColumn;

/**
 * An example to load a PHP array in Handsontable with an autocomplete column create from an ajax source
 */

$hd = new HandsontableSimple();
$data = [
    ['', 'Tesla', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
    ['2017', 10, 11, 12, 13, 15, 16],
    ['2018', 10, 11, 12, 13, 15, 16],
    ['2019', 10, 11, 12, 13, 15, 16],
    ['2020', 10, 11, 12, 13, 15, 16],
    ['2021', 10, 11, 12, 13, 15, 16]
];
$hd->setData($data);
$hd->setColumns([
    new ColumnConfig([
    'data' => 0,
    'type' => 'autocomplete',
    'source' => new AjaxSourceColumn('ajax/array.php')
    ]),
    new ColumnConfig()
    ]);
?>

<html>
    <br>
    <h3><b>Autocomplete with ajax</b></h3>
    <br>
    <!--other way to load handsontable-->
    <?= $hd->generateLibrairyContainerHTScript(true) ?>
</html>
?>