Skip to content

Latest commit

 

History

History
165 lines (121 loc) · 5.08 KB

02. Quick Start.md

File metadata and controls

165 lines (121 loc) · 5.08 KB

Quick Start

In this part, we will learn the following:

  • Requirements
  • Installation
  • Configuration
  • Basic Example

Requirements

Optional Requirements

Installation

Installation of this module uses composer. For Composer documentation, please refer to getcomposer.org.

Install the module:

$ php composer.phar require thadafinser/zfc-datagrid:dev-master

Enable the module by adding ZfcDatagrid key to your application.config.php file. Customize the module by copy-pasting the zfcdatagrid.local.php.dist file to your config/autoload folder.

Create the folder: data/ZfcDatagrid which will be used by ZfcDatagrid for caching.

Finally include the JS/CSS/Images files of the output that you want to use (Bootstrap files, jqGrid files...), the links of the required files are in the [Requirements](/docs/02. Quick Start.md#requirements)

Configuration

There are a lot of configurations you can override to customize the behaviour of your grid implementation.

You can find all options here (all options inside "ZfcDatagrid") https://github.com/ThaDafinser/ZfcDatagrid/blob/master/config/module.config.php

To override the configuration you should create a own config file for this module. Create: config/autoload/zfcdatagrid.local.php

Following configs are some of the currently available (taken from config/module.config.php):

return [
    'ZfcDatagrid' => [
        
        'settings' => [
            
            'default' => [
                'renderer' => [
                    'http' => 'bootstrapTable',
                    'console' => 'zendTable',
                ],
            ],
            
            'export' => [
                'enabled' => true,
                
                // currently only A formats are supported...
                'papersize' => 'A4',
                
                // landscape / portrait (we preferr landscape, because datagrids are often wide)
                'orientation' => 'landscape',
                
                'formats' => [
                    // renderer -> display Name (can also be HTML)
                    'PHPExcel' => 'Excel',
                    'tcpdf' => 'PDF',
                ],
                
                // The output+save directory
                'path' => 'public/download',
                
                'mode' => 'direct',
            ],
        ],
        
        'cache' => [
            
            'adapter' => [
                'name' => 'Filesystem',
                'options' => [
                    'ttl' => 720000, // cache with 200 hours,
                    'cache_dir' => 'data/ZfcDatagrid',
                ],
            ],
            'plugins' => [
                'exception_handler' => [
                    'throw_exceptions' => false
                ],
                
                'Serializer',
            ]
        ],
        
        'renderer' => [
            'jqGrid' => [
                'templates' => [
                    'layout' => 'zfc-datagrid/renderer/jqGrid/layout',
                ],
            ],
        ],
    ],
];

Basic Example

The first datagrid is a really simple one, to see if everything works for you. It'll work if you have ZF-Skeleton installed or Twitter Bootstrap included out of the box.

If you copy the following code and paste it into your action, try to call this action (with your defined route) and you should see your first ZfcDatagrid! (Congratulations) It's renderer with the output mode "bootstrapTable", where you can already paginate, filter and sort your data.

<?php
namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use ZfcDatagrid\Column;

class IndexController extends AbstractActionController
{

    /**
     * Simple bootstrap table
     *
     * @return \ZfcDatagrid\Controller\ViewModel
     */
    public function bootstrapAction()
    {
        $data = [
            ['displayName' => 'Mohammad ZeinEddin'],
            ['displayName' => 'John Wayne'],
            ['displayName' => 'Oprah Winfrey'],
        ];
        
        /* @var $grid \ZfcDatagrid\Datagrid */
        $grid = $this->getServiceLocator()->get('ZfcDatagrid\Datagrid');
        $grid->setTitle('Minimal grid');
        $grid->setDataSource($data);
        
        $col = new Column\Select('displayName');
        $col->setLabel('Name');
        $grid->addColumn($col);
        
        $grid->render();
        
        return $grid->getResponse();
    }
}

Navigation

  • Continue to [Columns](/docs/03. Columns.md)
  • Back to [Introduction](/docs/01. Introduction.md)
  • Back to the Index