复选框
- $row->getData($this->getColumn()->getIndex())
- $this->addColumn('in_products', array(
- 'header_css_class' => 'a-center',
- 'type' => 'checkbox',//datetime,date ,number
- 'field_name' => 'in_products',//checkbox name
- 'align' => 'center',
- 'index' => 'type',
- 'values' => array(1), //checked value list
- 'disabled_values' => array(1, 3),
- 'use_index' => true, //checkvalue=type false=pkid
- ));
下拉选框
- $this->addColumn('status',
- array(
- 'header'=> Mage::helper('catalog')->__('Status'),
- 'width' => '70px',
- 'index' => 'status',
- 'type' => 'options',
- 'options' => array('new'=>'待发货','sending'=>'发货中','complete'=>'完成')
- ));
自定义一列的内容
- protected function _prepareColumns() {
- $this->addColumn('address', array(
- 'header' => '地址',
- 'width' => '200',
- 'index' => 'address',
- 'renderer' => Test_Dispatching_Block_Adminhtml_Widget_Grid_Column_Renderer_Address
- ));
- return parent::_prepareColumns();
- }
- protected function _setFilterValues($data) { //自定义搜索
- foreach ($this->getColumns() as $columnId => $column) {
- if ($columnId == 'address' && isset($data[$columnId]) && strlen($data[$columnId]) > 0) {
- $fields = array('province' => 'province', 'city' => 'city', 'street' => 'street');
- $condition = array();
- $condition['province'] = array('like' => '%' . $data['address'] . '%');
- $condition['city'] = array('like' => '%' . $data['address'] . '%');
- $condition['street'] = array('like' => '%' . $data['address'] . '%');
- $this->getCollection()->addFieldToFilter($fields, $condition);
- $column->getFilter()->setValue($data[$columnId]);
- continue;
- }
- if (isset($data[$columnId]) && (!empty($data[$columnId]) || strlen($data[$columnId]) > 0) && $column->getFilter()) {
- $column->getFilter()->setValue($data[$columnId]);
- $this->_addColumnFilterToCollection($column);
- }
- }
- return $this;
- }
页面显示样式local/Test/Dispatching/Block/Adminhtml/Widget/Grid/Column/Renderer/Address.php
- <?php
- class Test_Dispatching_Block_Adminhtml_Widget_Grid_Column_Renderer_Address extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
- {
- public function render(Varien_Object $row)
- {
- $text = $row['province'] . $row['city'] . $row['county'] .$row['street'];
- return $text;
- }
- }
让Action根据行动态值显示action列表
- $this->addColumn('action', array(
- 'header' => '操作',
- 'width' => '50px',
- 'type' => 'action',
- 'getter' => 'getId', //action['field']的值
- 'actions' => array(
- array(
- 'caption' => '删除',
- 'url' => array('base' => '*/*/delete', /*'params'=>array('type'=>1)*/), //其他参数
- 'field' => 'order_id',
- 'filter' => array('status' => 'new') //出现的条件
- )
- ),
- 'filter' => false,
- 'sortable' => false,
- 'index' => 'stores',
- 'is_system' => true,
- 'renderer' => Test_Dispatching_Block_Adminhtml_Widget_Grid_Column_Renderer_Action
- ));
local/Test/Dispatching/Block/Adminhtml/Widget/Grid/Column/Renderer/Action.php
- <?php
- class Test_Dispatching_Block_Adminhtml_Widget_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
- {
- public function render(Varien_Object $row)
- {
- $actions = $this->getColumn()->getActions();
- if ( empty($actions) || !is_array($actions) ) {
- return ' ';
- }
- $i = 0;
- foreach ($actions as $action){
- if ( is_array($action) ) {
- if($this->_checkFiterAction($action, $row)) continue;
- if($i>0){
- $out .=" | ";
- }
- $out .= parent::_toLinkHtml($action, $row);
- }
- $i++;
- }
- return $out;
- }
- protected function _checkFiterAction($action, Varien_Object $row){
- $result = false;
- if(isset($action['filter']) && is_array($action['filter'])){
- foreach($action['filter'] as $key => $filter){
- if($row[$key] != $filter){
- $result = true;
- }
- }
- }
- return $result;
- }
- }
要实现各种功能就需要继承renderer