/** * Load the dataGrid */ private function loadDataGrid() { // filter category if ($this->categoryId != null) { // create datagrid $this->dgProducts = new BackendDataGridDB(BackendCatalogModel::QRY_DATAGRID_BROWSE_FOR_CATEGORY, array($this->categoryId, BL::getWorkingLanguage())); // set the URL $this->dgProducts->setURL('&category=' . $this->categoryId, true); } else { // dont filter category // create datagrid $this->dgProducts = new BackendDataGridDB(BackendCatalogModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage())); } // our JS needs to know an id, so we can highlight it $this->dgProducts->setRowAttributes(array('id' => 'row-[id]')); $this->dgProducts->enableSequenceByDragAndDrop(); $this->dgProducts->setColumnsHidden(array('category_id', 'sequence')); // check if this action is allowed if (BackendAuthentication::isAllowedAction('Edit')) { // set column URLs $this->dgProducts->setColumnURL('title', BackendModel::createURLForAction('edit') . '&id=[id]&category=' . $this->categoryId); // add edit and media column //$this->dgProducts->addColumn('media', null, BL::lbl('Media'), BackendModel::createURLForAction('media') . '&id=[id]', BL::lbl('Media')); $this->dgProducts->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit') . '&id=[id]&category=' . $this->categoryId, BL::lbl('Edit')); // set media column function $this->dgProducts->setColumnFunction(array(__CLASS__, 'setMediaLink'), array('[id]'), 'media'); } }
/** * Sets the column function to be executed for every row * * @param mixed $function The function to execute. * @param mixed $arguments The arguments to pass to the function. * @param mixed $columns The column wherein the result will be printed. * @param bool $overwrite Should the original value be overwritten. */ public function setColumnFunction($function, $arguments = null, $columns, $overwrite = true) { // call the parent parent::setColumnFunction($function, $arguments, $columns, $overwrite); // redefine columns $columns = (array) $columns; $attributes = null; // based on the function we should prepopulate the attributes array switch ($function) { // timeAgo case array('DataGridFunctions', 'getTimeAgo'): $attributes = array('class' => 'date'); $headerAttributes = array('class' => 'date'); break; } // add attributes if they are given if (!empty($attributes)) { // loop and set attributes foreach ($columns as $column) { $this->setColumnAttributes($column, $attributes); } } // add attributes if they are given if (!empty($headerAttributes)) { // loop and set attributes foreach ($columns as $column) { $this->setColumnHeaderAttributes($column, $attributes); } } }