It may be that your adminhtml
layout file is missing the grid.columnSet
block.
Without having your code, the most-likely issue is that you do not have your grid set up correctly. The reason that error would appear is this line:
$this->getColumnSet()->setSortable($this->getSortable());
$this->getColumnSet()
must be returning a boolean (mostl likely false).
/**
* Retrieve column set block
*
* @return \Magento\Backend\Block\Widget\Grid\ColumnSet
*/
public function getColumnSet()
{
return $this->getChildBlock('grid.columnSet');
}
So, $this->getChildBlock('grid.columnSet');
must be returning the boolean, instead of \Magento\Backend\Block\Widget\Grid\ColumnSet
. Let's dig in:
/**
* Retrieve child block by name
*
* @param string $alias
* @return \Magento\Framework\View\Element\AbstractBlock|bool
*/
public function getChildBlock($alias)
{
$layout = $this->getLayout();
if (!$layout) {
return false;
}
$name = $layout->getChildName($this->getNameInLayout(), $alias);
if ($name) {
return $layout->getBlock($name);
}
return false;
}
It looks like there are a few different reasons why this may be happening:
$this->getLayout()
returns false
. Most likely this is not the case.
- The
$alias
, whose value is 'grid.columnSet'
block is not found in layout as a child of the current block.
Here is a redacted version of what this looks like in the Newsletter module.
vendor/magento/module-newsletter/view/adminhtml/layout/newsletter_subscriber_block.xml
<block class="Magento\Backend\Block\Widget\Grid\ColumnSet" name="adminhtml.newslettrer.subscriber.grid.columnSet" as="grid.columnSet">
<arguments>
<argument name="id" xsi:type="string">problemGrid</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="subscriber_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">ID</argument>
<argument name="index" xsi:type="string">subscriber_id</argument>
<argument name="header_css_class" xsi:type="string">col-id</argument>
<argument name="column_css_class" xsi:type="string">col-id</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="email">
<arguments>
<argument name="header" xsi:type="string" translate="true">Email</argument>
<argument name="index" xsi:type="string">subscriber_email</argument>
<argument name="header_css_class" xsi:type="string">col-email</argument>
<argument name="column_css_class" xsi:type="string">ccol-email</argument>
</arguments>
</block>
<!-- snip -->
</block>