0

I currently have an admin grid view per file structure/code as below;

Block/Adminhtml/Things.php

public function __construct()
{
 $this->_controller = 'adminhtml_things';
 $this->_blockGroup = 'things';
 $this->_headerText = Mage::helper('things')->__('Things Grid');
 $this->_addButtonLabel = Mage::helper('things')->__('Create Enhanced News Item');
 parent::__construct();
}

Block/Adminhtml/Things/Grid.php

public function __construct()
{
 //... (Sorts etc)
 $this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
 $collection = Mage::getModel('things/things')->getCollection();
 //Use this in another Grid to filter
 //$collection->addFieldToFilter('customer_id', array('notnull' => true));
 $this->setCollection($collection);
 return parent::_prepareCollection();
}
protected function _prepareColumns()
{
 //... (columns)
 return parent::_prepareColumns();
}

controllers/Adminhtml/Things/ThingsController.php

public function indexAction() {
 $this->loadLayout();
 $this->renderLayout();
}
public function gridAction() {
 $this->loadLayout();
 $this->getResponse()->setBody($this->getLayout()->createBlock('things/adminhtml_things_grid')->toHtml());
}

layout/things/things.xml

<adminhtml_things_things_index>
 <reference name="content">
 <block type="things/adminhtml_things" name="things" />
 </reference>
</adminhtml_things_things_index>

and all works fine and I have a populated Grid view via adminurl/things_things/index (grid view)

but how do create another Grid View with filtered collection? Do I;

  1. Copy all the Block & controller files and rename/refactor the namespace (ie Things2) and add the view into the xml layout file or;
  2. Add another view action inside the ThingsController.php & xml layout file as well as creating another Grid block File with the collection filter ie Block/Adminhtml/Things/Grid2.php
asked Apr 2, 2016 at 9:36
1
  • I have tried to copy the files and change "things" to "things2" but I get the Fatal error: Call to a member function setSaveParametersInSession() on a non-object error Commented Apr 2, 2016 at 9:50

1 Answer 1

0

Used option 1 and refactored/renamed copied files of all the "things" & "Things" namings to "otherthings" & "Otherthings"..

But in the copied & renamed file Block/Adminhtml/Otherthings/Grid.php

I have not changed the _blockgroup

 $this->_blockGroup = 'things';//kept module name and not changed to "otherthings" naming

as this stopped the error that i explained in the comments i was getting and successfully got a new filtered collection grid view on a new backend url..

Plus..

As I only wanted to copied the Grid Files (and not the complete edit view & tab view files as not really wanting to edit two groups of file sets when file edts/improvents are needed) i needed the edit link in the grid view to point back to the original edit page url (ie adminurl/things_things/edit/id/13/key/3449574385634857) if not, I would get a 404, i changed the code in the edit column inside the copied grid file as per below;

//new copied file
Block/Adminhtml/Otherthings/Grid.php
//Edit Link Column point back to original edit url
$this->addColumn('action', array(
 'header' => Mage::helper('things')->__('Edit Item'),
 'width' => '100',
 'type' => 'action',
 'getter' => 'getId',
 'actions' => array(
 array(
 'caption' => Mage::helper('things')->__('Edit'),
 'url' => array(
 //point back to original edit URL
 'base' => '*/things_things/edit'
 ),
 'field' => 'id'
 )
 ),
 'filter' => false,
 'sortable' => false,
 'index' => 'stores',
 'is_system' => true
 ));
answered Apr 2, 2016 at 10:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.