Backend\Core\Engine\DataGrid::__construct PHP Method

__construct() public method

public __construct ( SpoonDatagridSource $source )
$source SpoonDatagridSource
    public function __construct(\SpoonDatagridSource $source)
    {
        parent::__construct($source);
        // set debugmode, this will force the recompile for the used templates
        $this->setDebug(BackendModel::getContainer()->getParameter('kernel.debug'));
        // set the compile-directory, so compiled templates will be in a folder that is writable
        $this->setCompileDirectory(BACKEND_CACHE_PATH . '/CompiledTemplates');
        // set attributes for the datagrid
        $this->setAttributes(array('class' => 'table table-hover table-striped fork-data-grid jsDataGrid'));
        // id gets special treatment
        if (in_array('id', $this->getColumns())) {
            // hide the id by defaults
            $this->setColumnsHidden('id');
            // our JS needs to know an id, so we can highlight it
            $this->setRowAttributes(array('id' => 'row-[id]'));
        }
        // set default sorting options
        $this->setSortingOptions();
        // add classes on headers
        foreach ($this->getColumns() as $column) {
            // set class
            $this->setColumnHeaderAttributes($column, array('class' => $column));
            // set default label
            $this->setHeaderLabels(array($column => \SpoonFilter::ucfirst(BackendLanguage::lbl(\SpoonFilter::toCamelCase($column)))));
        }
        // set paging class
        $this->setPagingClass('Backend\\Core\\Engine\\DataGridPaging');
        // set default template
        $this->setTemplate(BACKEND_CORE_PATH . '/Layout/Templates/Datagrid.tpl');
    }

Usage Example

Beispiel #1
0
 /**
  * @param string $query             The query to retrieve the data.
  * @param array  $parameters        The parameters to be used inside the query.
  * @param string $resultsQuery      The optional count query, used to calculate the number of results.
  * @param array  $resultsParameters The parameters to be used inside the results query.
  */
 public function __construct($query, $parameters = array(), $resultsQuery = null, $resultsParameters = array())
 {
     // results query?
     $results = $resultsQuery !== null ? array($resultsQuery, $resultsParameters) : null;
     // create a new source-object
     $source = new \SpoonDatagridSourceDB(BackendModel::get('database'), array($query, (array) $parameters), $results);
     parent::__construct($source);
 }