How do you make a grid in frontend?



  • Is it possible in frontend magegento 1 to make such a table hell?

    введите сюда описание изображения

    Or should we do a file in phtml using js library?

    I need advice, recommendation. Or a clue as to how to implement the standard grid



  • There are several options:

    1. Create a separate фабрикуfactory for a front-end module. Rander's on phtml, so I'll get something like that.

    2. It's possible to give access to the grinder of products and produce to the adminke, when a shark is created, and don't drink half the hell on the front. And just add some laser attribute and filter it.

    And then we'll figure out the first case of pseudo php.

    creating an abstract class in the directory. Block For example, the module will be Test_Frontgreed and analogy is being implemented from adminhtml

    file Block/Abstract.php

    abstract class Test_Frontend_Block_Abstract extends Core_Block_Template 
    {
       private $_collection = null;
       private $_columns = array();
    

    public function __construct()
    {
    $this->setTemplate('your/greed.phtml');
    }

    protected function _prepareCollection()
    {
    if($collection = $this->getData('collection') {
    // логика фильтрации коллекции
    $collection->load();
    return $collection;
    }
    }

    public function getCollection()
    {
    if(is_null($this->_collection)) {
    $this->_collection = $this->_prepareCollection();
    }

     return $this->_collection;
    

    }

    abstract public function prepareGrid(); //prepare grid

    protected function _addColumn($type,$key,$options)
    {
    $this->_columns[$key] = array(
    'type' => $type;
    'options' => $options;
    );
    }

    public function getCollumn() {
    if(count($this->_columns) == 0) {
    $this->prepareGrid();
    }
    return $this->_columns;
    }

    }

    Extended from previous

    class Test_Frontend_Block_Product extends Test_Frontend_Block
    {
    protected function _prepareCollection()
    {
    $collection = Mage::getModel('catalog/product')->getCollection();
    $this->setCollection();
    parent:_prepareCollection();
    }

    public function prepareGrid()
    {
    $this->_addColumn('text','entity_id',array('custom_options' => 'custom'));
    }
    }

    Well, the last thing to do is run the pattern.

    <?php foreach($this->getCollection() as $_product): ?>
    <tr>
    <?php foreach($this->getCollumn() as $_key => $_collumn): ?>
    <td><?php echo $_product->getData($_key) ?> </td>
    <?php endforeach; ?>
    <tr>
    <?php endforeach; ?>

    This is a simple example of a factory, although the second option should be preferable.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2