enter image description here

From them image above you can see the first record does not have name.

I want all the record which have name should be displayed and which doesn't have should not be listed in grid.

I know how to use addFieldToFilter in php file but don't know how to use in UI Grid.

        $collection =$this->MainOr->create()
            ->addFieldToFilter("parent_id", array("neq" => 0));
  • 1
    try this : magento.stackexchange.com/questions/95371/… – kunj Aug 24 '18 at 10:55
  • Ya but i am using UI component for listing – Avesh Naik Aug 24 '18 at 11:05
  • @avesh There is always a collection class linked with the ui grid, kindly check your module's di.xml , it should be there. Paste it here as well. – Anshu Mishra Aug 24 '18 at 11:51
  • Can you write the ans? – Avesh Naik Aug 24 '18 at 12:47
  • @AnshuMishra Element 'updater': This element is not expected. Line 9 ...... – Avesh Naik Aug 24 '18 at 13:54

Please add filter in collection.php with

 protected function _initSelect()
$this>addFieldToFilter("parent_id", array("neq" => 0));
return $this;

and extend collection.php in your grid/collection.php file

Try and Let me know if you want more help!!!

| improve this answer | |
  • Ma'am it's not working i inserted code in collection.php file – Avesh Naik Aug 24 '18 at 12:37
  • what error are you facing? – Rutvee Sojitra Aug 24 '18 at 12:48
  • You have to set your filter over here i have just give you a way that you can set filter over here $this>addFieldToFilter("parent_id", array("neq" => 0)); @avesh – Rutvee Sojitra Aug 24 '18 at 12:50
  • Ya i inserted the code in collection.php, model/ResourceModel/ModelName/Collection.php – Avesh Naik Aug 24 '18 at 12:51
  • Have you extend this collection in grid/collection? @avesh – Rutvee Sojitra Aug 24 '18 at 12:52

To add value to grid in ui component. Sample here. First you should see in view/adminhtml/ui_component/xxxx_listing.xml

 <dataSource name="xxxx_grid_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">CompanyName\ModuleName\Ui\DataProvider\XXXXX\VendorDataProvider</argument>
        <argument name="name" xsi:type="string">vendor_grid_data_source</argument>
        <argument name="primaryFieldName" xsi:type="string">entity_id</argument>
        <argument name="requestFieldName" xsi:type="string">id</argument>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="update_url" path="mui/index/render" xsi:type="url"/>
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>

That defind dataProvider CompanyName\ModuleName\Ui\DataProvider\XXXXX\VendorDataProvider

and class dataProvider will be like this.

   namespace CompanyName\ModuleName\Ui\DataProvider\Xxxxx;

   use Magento\Customer\Ui\Component\Listing\AttributeRepository;
     use Magento\Framework\Api\FilterBuilder;
    use Magento\Framework\Api\Search\SearchCriteriaBuilder;
    use Magento\Framework\App\RequestInterface;
    use Magento\Framework\View\Element\UiComponent\DataProvider\Reporting;
     use Magento\Framework\Api\Search\SearchResultInterface;
    use CompanyName\ModuleName\Model\ResourceModel\XXXXX\CollectionFactory;

   class VendorDataProvider extends 

 * @var AttributeRepository
private $attributeRepository;

 * @param string                $name
 * @param string                $primaryFieldName
 * @param string                $requestFieldName
 * @param Reporting             $reporting
 * @param SearchCriteriaBuilder $searchCriteriaBuilder
 * @param RequestInterface      $request
 * @param FilterBuilder         $filterBuilder
 * @param AttributeRepository   $attributeRepository
 * @param array                 $meta
 * @param array                 $data
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
public function __construct(
    Reporting $reporting,
    SearchCriteriaBuilder $searchCriteriaBuilder,
    RequestInterface $request,
    FilterBuilder $filterBuilder,
    AttributeRepository $attributeRepository,
    array $meta = [],
    array $data = []
) {
    $this->attributeRepository = $attributeRepository;


 * @param SearchResultInterface $searchResult
 * @return array
protected function searchResultToOutput(SearchResultInterface $searchResult)
    $arrItems = [];
    $arrItems['totalRecords'] = $searchResult->getTotalCount();

    $arrItems['items'] = [];
    foreach ($searchResult->getItems() as $item) {
        $arrItems['items'][] = $item->getData();

    return $arrItems;

 * {@inheritdoc}
public function getData()
    $collection = $this->getSearchResult();

    $data = $this->searchResultToOutput($collection);

    return $data;

you can rewrite function getData to addAttributeToSelect for collection. Then it will show result to grid. If it work please vote for me. :)

| improve this answer | |

@Rutvee Sojitra, I applied the changes but nothing reflects, also extended the collection.php in the grid collection. Can you help me..

| improve this answer | |
  • What error you are getting? – Avesh Naik May 5 at 11:38
  • Issue resolved thanks applied some different solution. – Pratibha Verma Jun 20 at 8:47

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.