PHP code example of jgm / tablebundle

1. Go to this page and download the library: Download jgm/tablebundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jgm / tablebundle example snippets


// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...,
            new JGM\TableBundle\JGMTableBundle()
        );
        // ...
    }
    // ...
}

// src/YourBundle/Table/Type/StudentTableType.php
class StudentTableType extends JGM\TableBundle\Table\Type\AbstractTableType
{
    public function buildTable(TableBuilder $builder) 
    {
		$builder
			->add('text', 'name', ['label' => 'Name'])
			->add('number', 'term', ['label' => 'Term'])
			->add('date', 'birthday', ['label' => 'Day of birth']);
    }

    public function getDataSource(ContainerInterface $container)
    {
      return new EntityDataSource('YourBundle:Student');
    }

    public function getName()
    {
        return 'student_table';
    }

    public function configureOptions(OptionsResolver $resolver)
    {
		$optionsResolver->setDefaults(array(
			'attr' => array('width' => '600px', 'class' => 'table-css'),
			'empty_value' => 'There is no student...'
		));
    }
}

// src/YourBundle/Controller/StudentController.php
<?
class StudentController extends Symfony\Bundle\FrameworkBundle\Controller\Controller
{
    public function showAction()
    {
        $table = $this->get('jgm.table')->createTable(new StudentTableType());
		return array('studentTable' => $table->createView());
    }
}