1

I have created a custom module with grid. See below image: enter image description here

Column product sku is render using product_id

<column name="product_id" class="Lime\SN\Ui\Component\Listing\Column\ProductSku">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="label" translate="true" xsi:type="string">Product SKU</item>

            </item>
        </argument>
    </column>

I want to add filter on renderer column, but its not working, how can I custom default filter function in magento 2?

enter image description here

0

1 Answer 1

-1

You need to add <item name="filter" xsi:type="string">select</item> to your filed

Don't renderer whole field, just renderer option like this

<column name="product_id">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Lime\SN\Ui\Component\Listing\Column\ProductSku</item>
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">select</item>
            <item name="label" xsi:type="string" translate="true">Product SKU</item>
            <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
            <item name="dataType" xsi:type="string">select</item>
            <item name="editor" xsi:type="array">
            <item name="editorType" xsi:type="string">select</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                </item>
            </item>
        </item>
    </argument>
</column>

Now pass option array to toOptionArray at ProductSku.php

Lime\SN\Ui\Component\Listing\Column\ProductSku.php

<?php

namespace Lime\SN\Ui\Component\Listing\Column;

class ProductSku implements \Magento\Framework\Option\ArrayInterface
{
    private $skuCollection;

    public function __construct(
        //construct Class
    ) {
        //define variable
    }

    public function toOptionArray()
    {
        $skuArr = [];

        // You logic here

        return $skuArr;
    }
}
3
  • Is there any other way than using select ?, your answer is great though, thanks, but Im planning to use this filter in customer name too, and if Im using select, i think there will be too many option,
    – samani
    Aug 8, 2017 at 6:20
  • @samani, No there are no any other way to filter data. You must use select, list or multiselect for filter data. You can limit data of array in toOptionArray() if you have big amount of data. Aug 8, 2017 at 6:32
  • so we cant modify filter query to get the collection? for example function 'filter_condition_callback' in magento 1, i want to use similar function in magento 2,
    – samani
    Aug 9, 2017 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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