0

I have created a grid under tabGrid created by block

Everything is working fine except the category filter,data under category column is shown using renderer. When I change the value in dropdown , the loader just keeps loading. Please help if any one knows what I have skipped.

  • can you please add the code, how you added category dropdown – Abhishek Panchal Nov 27 '17 at 14:33
  • //adding category column to grid $this->addColumn( 'category_ids', [ 'header' => __('Category'), 'index' => 'name', 'class' => 'xxx', 'width' => '50px', 'type' => 'options', 'options' => $this->getCategoryOptions(), 'renderer'=> 'Vendor\Assigncategory\Block\Adminhtml\Assigncategory\Edit\Tab\Renderer\Category', ] ); – Vicky Nov 28 '17 at 7:32
0

I have facing same issue for grid.

I have found the solution. It's work fine for me.

protected function _prepareCollection()
{
    if(!empty($this->getCustomerGroupIds())) {
        $customerGroupIds = $this->getCustomerGroupIds();
    } else if(!empty($this->backendSession->getCustomerGroupIds())) {
        $customerGroupIds = $this->backendSession->getCustomerGroupIds();
        $this->backendSession->unsCustomerGroupIds();
    } else {
        $customerGroupIds = [];
    }


    $customerCollections = $this->customerFactory->create();
    $customerCollections->joinAttribute('country_id', 'customer_address/country_id', 'default_billing', null, 'left');
    $customerCollections->addFilterToMap('country_id', 'customer_address.country_id');
    $customerCollections->addFieldToFilter('group_id', ['in' => $customerGroupIds]);
    $this->setCollection($customerCollections);

    return parent::_prepareCollection();
}

protected function _addColumnFilterToCollection($column)
{
    // Set custom filter for in customer flag        
    if ($column->getId() == 'customer_ids') {
        $customerIds = $this->_getSelectedCustomers();
        if (empty($customerIds)) {
            $customerIds = 0;
        }
        if ($column->getFilter()->getValue()) {
            $this->getCollection()->addFieldToFilter('entity_id', ['in' => $customerIds]);
        } else {
            if ($customerIds) {
                $this->getCollection()->addFieldToFilter('entity_id', ['nin' => $customerIds]);
            }
        }
    } else if($column->getId() == 'country_id') {
        $this->getCollection()->addFieldToFilter('country_id', ['eq' => $column->getFilter()->getValue()]);            
    } else {
        parent::_addColumnFilterToCollection($column);
    }

    return $this;
}

I have done it for customer country_id.

Hope its help you. Let me know if you have any query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.