public function testRightExtraColumn() { $select = $this->db->select()->from('unit'); $this->grid->setSource(new Bvb_Grid_Source_Zend_Select($select)); $right = new Bvb_Grid_Extra_Column(); $right->title('Right')->decorator('test')->name('test')->position('right'); $this->grid->addExtraColumns($right); $grid = $this->grid->deploy(); $this->controller->getResponse()->setBody($grid); $this->assertQueryContentContains("/div/table/tr[2]/th[16]", 'Right'); }
public function listAction() { $config = new Zend_Config_Ini(BASE_PATH . DIRECTORY_SEPARATOR . "configs" . DIRECTORY_SEPARATOR . "grid.ini", 'production'); $grid = Bvb_Grid::factory('Table', $config); $data = $this->_listdata(); // echo "<pre>"; //print_r($data);exit; $source = new Bvb_Grid_Source_Array($data); $grid->setSource($source); $grid->setImagesUrl('/grid/'); $editColumn = new Bvb_Grid_Extra_Column(); $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); $editColumn->setPosition('right')->setName('Edit')->setDecorator("<a href=\"{$baseUrl}/admin/menu/edit/id/{{front_menu_id}}\">Edit</a><input class=\"address-id\" name=\"address_id[]\" type=\"hidden\" value=\"{{front_menu_id}}\"/>"); $deleteColumn = new Bvb_Grid_Extra_Column(); $deleteColumn->setPosition('right')->setName('Delete')->setDecorator("<a class=\"delete-data\" href=\"{$baseUrl}/menu/delete/id/{{front_menu_id}}\">Delete</a>"); $grid->addExtraColumns($editColumn, $deleteColumn); $grid->updateColumn('front_menu_id', array('hidden' => true)); $grid->updateColumn('del', array('hidden' => true)); $grid->setRecordsPerPage(20); $grid->setPaginationInterval(array(5 => 5, 10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100)); $grid->setExport(array('print', 'word', 'csv', 'excel', 'pdf')); $this->view->grid = $grid->deploy(); }
/** * This example allow you to create an horizontal row, for every distinct value from a field * */ public function hrowAction() { $grid = $this->grid(); $grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('Country', array('Name', 'Continent', 'Population', 'LifeExpectancy', 'GovernmentForm', 'HeadOfState'))->limit(1000)->order('Continent ASC'))); $grid->setNoFilters(1); $grid->setNoOrder(1); $grid->setRecordsPerPage(1200); $grid->updateColumn('Name', array('title' => 'Country')); $grid->updateColumn('Continent', array('title' => 'Continent', 'hRow' => 1)); $grid->updateColumn('Population', array('title' => 'Population', 'class' => 'width_80')); $grid->updateColumn('LifeExpectancy', array('title' => 'Life E.', 'class' => 'width_50', 'decorator' => '<b>{{LifeExpectancy}}</b>')); $grid->updateColumn('GovernmentForm', array('title' => 'Government Form')); $grid->updateColumn('HeadOfState', array('title' => 'Head Of State')); $grid->setSqlExp(array('Population' => array('functions' => array('SUM')))); $extra = new Bvb_Grid_Extra_Column(); $extra->position('right')->name('Right')->decorator("<input class='input_p'type='text' value=\"{{Population}}\" size=\"3\" name='number[]'>"); $esquerda = new Bvb_Grid_Extra_Column(); $esquerda->position('left')->name('Left')->decorator("<input type='checkbox' name='number[]'>"); $grid->addExtraColumns($extra, $esquerda); $this->view->pages = $grid->deploy(); $this->render('index'); }
/** * Add extra columns * * @return Bvb_Grid */ public function addExtraColumns($columns = array()) { static $order = 10; if (is_array($columns)) { $extraColumns = $columns; } else { $extraColumns = func_get_args(); } if (count($extraColumns) == 0) { throw new Bvb_Grid_Exception('No Columns To Add'); } $this->emitEvent('grid.add_extra_columns', array('columns' => $extraColumns)); foreach ($extraColumns as $value) { if (!$value instanceof Bvb_Grid_Extra_Column) { $value = new Bvb_Grid_Extra_Column($value['name'], $value); #throw new Bvb_Grid_Exception($value . ' must be a instance of Bvb_Grid_Extra_Column'); } if (!$value->getOption('name') || !is_string($value->getOption('name'))) { throw new Bvb_Grid_Exception('You need to define the column name'); } if ($value->getOption('title') && !is_string($value->getOption('title'))) { throw new Bvb_Grid_Exception('title option must be a string'); } if (!$value->getOption('position') || !in_array($value->getOption('position'), array('left', 'right'))) { throw new Bvb_Grid_Exception('Please define column position (left|right)'); } if (!$value->getOption('order')) { $order++; $value->setOption('order', $order); } $this->_extraColumns[$value->getOption('name')] = $value->getColumn(); } return $this; }
/** * Builds Mass Actions * * @return string */ protected function _buildMassActions() { if (!$this->getMassActions()->hasMassActions()) { return false; } $pk = $this->_getMassActionsDecorator(); $left = new Bvb_Grid_Extra_Column(); $decorator = "<input type='checkbox' onclick='observeCheckBox_" . $this->getGridId() . "(this)' " . "id='massCheckBox_" . $this->getGridId() . "' value='" . $pk . "' />"; $left->position('left')->title('')->name('ZFG_MASS_ACTIONS')->decorator($decorator); $this->addExtraColumns($left); $select = array(); foreach ($this->getMassActions()->getMassActionsOptions() as $value) { $select[$value['url']] = $value['caption']; } $formSubmitOptions = array_merge(array('onClick' => "return convertArrayToInput_" . $this->getGridId() . "()"), $this->getMassActions()->getSumitAttributes()); $formSelect = $this->getView()->formSelect("gridAction_" . $this->getGridId(), null, array(), $select); $formSubmit = $this->getView()->formSubmit("send_" . $this->getGridId(), $this->__('Submit'), $formSubmitOptions); if ($this->getRecordsPerPage() < $this->getTotalRecords()) { $currentRecords = $this->getRecordsPerPage(); } else { $currentRecords = $this->getTotalRecords(); } $ids = $this->getSource()->getMassActionsIds($this->_data['table'], $this->getMassActions()->getFields(), $this->getMassActions()->getMultipleFieldsSeparator()); $cssClasses = $this->getTemplateParams(); if (!isset($cssClasses['cssClass'])) { $cssClasses['cssClass'] = ''; } $cssClasses = $cssClasses['cssClass']; $cssClasses['massActions'] = isset($cssClasses['massActions']) ? " class='{$cssClasses['massActions']}'" : ''; $cssClasses['massSelect'] = isset($cssClasses['massSelect']) ? " class='{$cssClasses['massSelect']}'" : ''; $return = "<tr><td " . $cssClasses['massActions'] . " colspan=" . $this->_colspan . ">" . "<form style=\"padding:0;margin:0;\" method=\"post\" action=\"\" " . " id=\"massActions_{$this->getGridId()}\" name=\"massActions_{$this->getGridId()}\">" . $this->getView()->formHidden('massActionsAll_' . $this->getGridId(), $ids) . $this->getView()->formHidden('postMassIds' . $this->getGridId(), '') . "<span " . $cssClasses['massSelect'] . ">" . "<a href='#' onclick='checkAll_" . $this->getGridId() . "" . "(document.massActions_" . $this->getGridId() . ".gridMassActions_" . $this->getGridId() . "," . "{$this->getTotalRecords()},1);return false;'>" . $this->__('Select All') . "</a> | " . "<a href='#' onclick='checkAll_" . $this->getGridId() . "" . "(document.massActions_" . $this->getGridId() . ".gridMassActions_" . $this->getGridId() . "," . "{$currentRecords},0);return false;'>" . $this->__('Select Visible') . "</a> | " . "<a href='#' onclick='uncheckAll_" . $this->getGridId() . "" . "(document.massActions_" . $this->getGridId() . ".gridMassActions_" . $this->getGridId() . ",0); " . "return false;'>" . $this->__('Unselect All') . "</a> | <strong>" . "<span id='massSelected_" . $this->getGridId() . "'>0</span></strong> " . $this->__('items selected') . "</span> " . $this->__('Actions') . ": {$formSelect} {$formSubmit}" . "</form></td></tr>"; return $return; }