Example #1
0
 protected function setUp()
 {
     parent::setUp();
     $this->_layoutMock = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface');
     $context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Backend\\Block\\Template\\Context', ['layout' => $this->_layoutMock]);
     $this->_block = $this->_layoutMock->createBlock('Magento\\Backend\\Block\\Widget\\Grid\\Extended', 'grid', ['context' => $context]);
     $this->_block->addColumn('column1', ['id' => 'columnId1']);
     $this->_block->addColumn('column2', ['id' => 'columnId2']);
 }
Example #2
0
 public function addColumn($columnId, $column)
 {
     if (is_array($column)) {
         if (!array_key_exists('header_css_class', $column)) {
             $column['header_css_class'] = 'grid-listing-column-' . $columnId;
         }
         if (!array_key_exists('column_css_class', $column)) {
             $column['column_css_class'] = 'grid-listing-column-' . $columnId;
         }
     }
     return parent::addColumn($columnId, $column);
 }
Example #3
0
 /**
  * Add column to grid
  * Overridden to add support for visibility_filter column option
  * It stands for conditional visibility of the column depending on filter field values
  * Value of visibility_filter supports (filter_field_name => filter_field_value) pairs
  *
  * @param string $columnId
  * @param array $column
  * @return $this
  */
 public function addColumn($columnId, $column)
 {
     if (is_array($column) && array_key_exists('visibility_filter', $column)) {
         $filterData = $this->getFilterData();
         $visibilityFilter = $column['visibility_filter'];
         if (!is_array($visibilityFilter)) {
             $visibilityFilter = array($visibilityFilter);
         }
         foreach ($visibilityFilter as $k => $v) {
             if (is_int($k)) {
                 $filterFieldId = $v;
                 $filterFieldValue = true;
             } else {
                 $filterFieldId = $k;
                 $filterFieldValue = $v;
             }
             if (!$filterData->hasData($filterFieldId) || $filterData->getData($filterFieldId) != $filterFieldValue) {
                 return $this;
                 // don't add column
             }
         }
     }
     return parent::addColumn($columnId, $column);
 }