0

How to create Admin Grid Without Form in magento 2 . I don't need form i Just Want Grid with my content I am referring to Cache or Re indexing kind of Grid is this possible to achieve that I tried with rendering but its not done Can you please help me on this to achieve that feature

Screenshot for reference below: enter image description here

Magento\SampleForm\view\adminhtml\ui_component\sampleform_form.xml

<listing  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/Ui/etc/ui_configuration.xsd">
  <dataSource name="sampleform_form_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Magento\SampleForm\Model\DataProvider</argument>
            <argument name="name" xsi:type="string">sampleform_form_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">entity_id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
        </argument>
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
            </item>
        </argument>
    </dataSource> 


 <columns name="mysampleform">
    <column name="entity_id">
        <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">entity_id</item>
            </item>
        </argument>
    </column>

     <column name="color">
        <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">color</item>
            </item>
        </argument>
    </column>

    <column name="title">
        <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">title</item>
            </item>
        </argument>
    </column>

     </columns>

 </listing>

Magento\SampleForm\view\adminhtml\layout\sampleform_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left"  xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <head>
        <title>
            Test Content By Ankit
        </title>
        <css src="Magento_SampleForm::css/color-select.css"/>
    </head>
    <update handle="styles"/>
    <body>
        <referenceContainer name="content">
            <uiComponent name="sampleform_form"/>
        </referenceContainer>
    </body>
</page>
MackieeE
  • 232
  • 4
  • 15
magento12345
  • 471
  • 1
  • 9
  • 20

1 Answers1

0

In Magento 1 as in Magento 2, grids and forms are two different things.
You can create a grid without a form and a form without a grid. The two are often linked but this is not an obligation.

To create a grid in Magento 2 you have to use the listing UI Component.
Here you can find more informations about them :

If you want an example on how to create one you can take a look at CMS pages in Magento_Cms module.
You have to create a ui_component : magento/module-cms/view/adminhtml/ui_component/cms_page_listing.xml

Here you can find a complete explanation https://magento.stackexchange.com/a/97891/33619

Matthéo Geoffray
  • 2,684
  • 2
  • 20
  • 45
  • thankf for reply but i dont want grid like below Screen shot i want only cache or reindex grid https://www.screencast.com/t/2dXVT8mlIQE – magento12345 Jan 24 '17 at 17:19
  • Yes that is the same answer, you have to use ui_component anyway. The only thing that will change is the DataProvider class. – Matthéo Geoffray Jan 24 '17 at 17:22
  • I added screen what i need i updated my question please check – magento12345 Jan 24 '17 at 17:22
  • In the ui_component declaration you don't have to add buttons, search bar, etc you can do a simple ui_component with only column and DataProvider class. But you definitly have to use ui components ;) – Matthéo Geoffray Jan 24 '17 at 17:24
  • i tried this sample module https://github.com/magento/magento2-samples/blob/master/sample-module-form-uicomponent/README.md but i am getting error Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Call to a member function addFieldToFilter() on null in E:\Personal\Project\xampp\htdocs\magento2\vendor\magento\module-ui\Component\Wrapper\UiComponent.php on line 0 – magento12345 Jan 24 '17 at 18:13
  • I fixed that above error now i am able to see the static content How to add column now i referred cms_page_listing.xml but unable to add can you please help on this – magento12345 Jan 24 '17 at 19:07
  • You add columns with the nodes <columns><column/></columns>. Here you can find an example : https://github.com/magento/magento2/blob/develop/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml#L163 – Matthéo Geoffray Jan 24 '17 at 22:25
  • :i updated my question with solution what you suggested But its not showing column . Its showing only head content which i declated in xml – magento12345 Jan 25 '17 at 04:37
  • I got the grid now now can you please tell me how to get Data inside that grid same as like cache grid for reference – magento12345 Jan 25 '17 at 08:43
  • You have to use a DataProvider. Here is a tuto explaining DataProvider and grid : https://www.maximehuran.fr/en/create-adminhtml-grid-with-magento-2/ and there is a question I asked about custom DataProvider : http://magento.stackexchange.com/a/150283/33619. Please also check the DataProvider declaration in magento/module-cms/etc/di.xml:59 and the class of the DataProvider \Magento\Cms\Model\Page\DataProvider – Matthéo Geoffray Jan 25 '17 at 09:16
  • I tried same as cms one but unable to implement in my module now my module it look like https://www.screencast.com/t/GhXjCp0ZXGoj i referred cache.xml also but no luck can you please help on this – magento12345 Jan 25 '17 at 09:37
  • i checked dataprovider for cms block its reading data from database but in my case i do not have database form i want to read Magento cache is reading data like https://github.com/magento/magento2/blob/develop/app/code/Magento/Store/etc/cache.xml – magento12345 Jan 25 '17 at 09:42
  • Your DataProvider is a collection with a table in database ? – Matthéo Geoffray Jan 25 '17 at 09:42
  • Did you check that link ? It is how to use a custom DataProvider : http://magento.stackexchange.com/a/150283/33619. In that case it reads file from server but you can easily change. – Matthéo Geoffray Jan 25 '17 at 09:44
  • Did you checked ? – magento12345 Jan 26 '17 at 08:50