Skip to content

jfsimon/datagrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A datagrid component for PHP Build Status

The main goal of this component is to render a result set from any data source as an HTML table with sorting and filtering capabilities (ideal for backends). This component aims to be framework-agnostic and provide bindings for most used PHP frameworks.

To see the component in action, you can check accptance tests:


Create CRUD actions:

$actions = Actions::enable()
    ->addGlobalRoute('create', 'beatle_create')
    ->addEntityRoute('read', 'beatle_read', array('beatle' => 'slug'))
    ->addEntityRoute('update', 'beatle_update', array('beatle' => 'slug'))
    ->addEntityRoute('delete', 'beatle_delete', array('beatle' => 'slug'))
;

1 - Usage with custom data:

$beatles = array(
  array('slug' => 'john',    'name' => 'John Lenon',       'birthday' => new \DateTime('1940-10-09'), 'alive' => false),
  array('slug' => 'paul',    'name' => 'Paul McCartney',   'birthday' => new \DateTime('1942-06-18'), 'alive' => true),
  array('slug' => 'georges', 'name' => 'Georges Harrison', 'birthday' => new \DateTime('1943-02-25'), 'alive' => false),
  array('slug' => 'ringo',   'name' => 'Ringo Starr',      'birthday' => new \DateTime('1940-07-07'), 'alive' => true),
);
$schema = Schema::create()
    ->add('name', 'string', array('label' => 'Member name')
    ->add('birthday', 'datetime', array('time_format' => \IntlDateFormatter::NONE))
    ->add('alive', 'boolean', array('label' => 'Still alive?', 'false_value' => 'no more :('))
;
$factory = new Factory();
$grid = $factory->createGrid(new Collection($beatles), array('schema' => $schema, 'actions' => $actions));
echo  $this->getTwig()->render('{{ datagrid(grid) }}', array('grid' => $grid));

2 - Usage with Doctrine:

$factory = new DoctrineFactory($em);
echo $factory
    ->createGrid(new Collection($em->findAll('Beatle')), array('actions' => $actions))
    ->render(new TwigRenderer($twig, 'beatles.html.twig'));

Both will render:

Member name Birthday Still alive? Create
John Lenon Oct 9, 1940 no more :( Read Update Delete
Paul McCartney Jun 18, 1942 yes Read Update Delete
Georges Harrison Feb 25, 1943 no more :( Read Update Delete
Ringo Starr Jul 7, 1940 yes Read Update Delete

About

A PHP datagrid component

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages