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.