2013-01-04 31 views
6

Mam problem z filtrem w moim module w siatce administratora.Filtr w siatce z niestandardowym rendererem

Mój problem: Filtr do kolumn z niestandardowym rendererem nie działa.

public function _prepareColumns() 
    { 
     $this->addColumn('entity_id', array(
      'header' => 'ID', 
      'index' => 'entity_id', 
      'width' => '30px' 
     )); 
     $this->addColumn('author', array(
      'header' => 'Author', 
      'index' => 'author', 
      'renderer' => 'Test_Block_Adminhtml_Vj_Renderer_Author' 
     )); 

renderujący jest

class Test_Block_Adminhtml_Vj_Renderer_Author extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract 
{ 
    public function render(Varien_Object $row) 
    { 
     $value = $row->getData($this->getColumn()->getIndex()); 
     $autor = Mage::getModel('test/test')->load($value); 
     return ($author->getName() . ' ' . $author->getSurname()); 
    } 
} 

Autor w sieci pokazuje dobrze na przykład „George Bush”, ale gdy próbuję pisać do filtrowania (na przykład „Bu”) return filtr zerowego rzędu. : -/

Każdy pomysł? Thx.

Odpowiedz

14

Ten artykuł może pomóc ... http://www.atwix.com/magento/grid-filter-for-columns/

Na addColumn() zadzwonić do pola niestandardowego, dodać coś takiego ...

'filter_condition_callback' => array($this, '_myCustomFilter'),

Następnie dodać metodę filtra (zmieniając "gdzie()" w razie potrzeby) ...

protected function _myCustomFilter($collection, $column) 
{ 
    if (!$value = $column->getFilter()->getValue()) { 
     return $this; 
    } 

    $this->getCollection()->getSelect()->where(
     "my_field like ?" 
    , "%$value%"); 


    return $this; 
} 
+0

próbuję filtrować zbiór atrybutów za pomocą atrybutu id działa dla pojedynczej wartości, takiej jak ta $ this-> getCollection() -> getSelect() -> where ( "main_table.attribute_id =?" , 173, 226); , ale chcę filtrować wiele identyfikatorów i kiedy próbuję tego. $ this-> getCollection() -> getSelect() -> where ( "main_table.attribute_id IN?" , array (173, 226)); Wystąpił błąd Wystąpił błąd w składni SQL –

Powiązane problemy