2

I have created a custom module for backend with 3 columns like this:

  1. PostAction.php located in vendor\namespace\Ui\Component\Listing\Column

    class PostActions extends \Magento\Ui\Component\Listing\Columns\Column {

    public function prepareDataSource(array $dataSource)
        {
            if (isset($dataSource['data']['items'])) {
                foreach ($dataSource['data']['items'] as & $item) {
                    if (isset($item['id'])) {
                        $item[$this->getData('name')] = [
                            'edit' => [
                                'href' => $this->_urlBuilder->getUrl(
                                    static::URL_PATH_EDIT,
                                    [
                                        'id' => $item['id']
                                    ]
                                ),
                                'label' => __('Edit')
                            ],
                            'delete' => [
                                'href' => $this->_urlBuilder->getUrl(
                                    static::URL_PATH_DELETE,
                                    [
                                        'id' => $item['id']
                                    ]
                                ),
                                'label' => __('Delete'),
                                'confirm' => [
                                    'title' => __('Delete "${ $.$data.name }"'),
                                    'message' => __('Are you sure you wan\'t to delete the Post "${ $.$data.name }" ?')
                                ]
                            ]
                        ];
                    }
                }
            }
            return $dataSource;
        }
    

    }

my UI commpoents where i added the columns:

<column name="id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="sorting" xsi:type="string">asc</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                </item>
            </argument>
        </column>
        <column name="name">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="label" xsi:type="string" translate="true">Name</item>
                </item>
            </argument>
        </column>
        <column name="email" class="vendor\namespace\Ui\Component\Listing\Column\PostActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="label" xsi:type="string" translate="true">Email</item>
                </item>
            </argument>
        </column>

In my admin i see only 2 colums: the column with ID and Name, but the column with email doesn't appear at all. I have tried to add the column in manny ways but no success. I have tried like this also:

<column name="email">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="sorting" xsi:type="string">asc</item>
                    <item name="label" xsi:type="string" translate="true">Email</item>
                </item>
            </argument>
        </column>

Does anyone know what I'am doing wrong?

  • try using <item name="filter" xsi:type="string">text</item> and remove class from it. And why is uicomponent form file and the column you are showing are different. As I see you have added email column email as action column. – Priyank Sep 11 '17 at 13:34
  • i have tried but no success – Alin Lupoiu Sep 11 '17 at 13:45
1

I was not careful and I forgot about the "column" option and my column was not selected.

Maybe this will help someone.

enter image description here

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.