PHP code example of fsi / datagrid

1. Go to this page and download the library: Download fsi/datagrid 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/ */

    

fsi / datagrid example snippets




$grid = $this->get('datagrid.factory')->createDataGrid();



$grid->addColumn('id', 'number', array('label' => 'Id'))
     ->addColumn('title', 'text', array('label' => 'News Title'))
     ->addColumn('author', 'text', array(
            'field_mapping' => array(
                'author_name',
                'author_surname',
                'author_email'
            ),
            'value_glue' => '<br/>',
            'label' => 'Author'
        )
    )
    ->addColumn('publication', 'datetime', array(
            'field_mapping' => array('publication_date'),
            'value_format' => 'Y.m.d H:i:s',
            'label' => 'Author'
        )
    )
    ->addColumn('action', 'action', array(
            'label' => 'Actions',
            'field_mapping' => array('id'),
            'actions' => array(
                'edit' => array(
                    'route_name' => '_edit_news',
                    'parameters_field_mapping' => array('id' => 'id'),
                ),
                'delete' => array(
                    'route_name' => '_delete_news',
                    'parameters_field_mapping' => array('id' => 'id'),
                )
            )
        )
    );



$view = $grid->createView();

<table>
    <tr>
     foreach ($view->getColumns() as $column):



$columns = $view->getColumns();
foreach ($columns as $column) {
    // this will give you access to ``HeaderView`` object.
    echo $column->getLabel();
}

// this will give you access to ``CellView`` object.
$cell = $view['name'];
echo $cell->getValue();
 php


namespace FSi\SiteBundle\Entity\News;

class News
{
    /**
     * @var integer
     */
    protected $id;

    /**
     * @var string
     */
    protected $title;

    /**
     * @var string
     */
    protected $author_name;

    /**
     * @var string
     */
    protected $author_surname;

    /**
     * @var string
     */
    protected $author_email;

    /**
     * @var DateTime
     */
    protected $publication_date;

    public function getId()
    {
        return $this->id;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function getAuthorName()
    {
        return $this->author_name;
    }

    public function getAuthorSurname()
    {
        return $this->author_surname;
    }

    public function getAuthorEmail()
    {
        return $this->author_email;
    }

    public function getPublicationDate()
    {
        return $this->publication_date;
    }

    /*
    Here we should have setters
    public function setTitle($title)
    public function setAuthorName($name)
    ...
    */
}
 php


$data = $this->getEntityManager()->getRepository('FSi\SiteBundle\Entity\News')->findAll();