0

Here I want to display only those data who have emailstatus=1 from my custom table. Here I have XML code. file-path: app/code/chirag/stockproduct/view/adminhtml/layout/stockproduct_index_newlist.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>
            Out of Stock Product Notifier : Display New List
        </title>
    </head>
    <body>
        <!-- <referenceContainer name="content">
            <block class="Magento\Backend\Block\Template" template="Chirag_Stockproduct::displayalldata.phtml"/>
        </referenceContainer> -->
        <referenceContainer name="content">
            <argument name="data" xsi:type="array">
                <item name="spinner" xsi:type="string">spinner_columns</item>
                <item name="buttons" xsi:type="array">
                    <item name="add" xsi:type="array">
                        <item name="name" xsi:type="string">add</item>
                        <item name="label" xsi:type="string" translate="true">Add New Post</item>
                        <item name="class" xsi:type="string">primary</item>
                        <item name="url" xsi:type="string">*/*/new</item>
                    </item>
                </item>
            </argument>
            <!-- <block class="Chirag\Stockproduct\Block\Adminhtml\Test" name="mageplaza_post_grid"> -->
                <block class="Magento\Backend\Block\Widget\Grid" name="stockproduct_all_grid.grid" as="grid">
                    <arguments>
                        <argument name="id" xsi:type="string">id</argument>
                        <argument name="dataSource" xsi:type="object">Chirag\Stockproduct\Model\ResourceModel\Test\Newlistcollection
                            <!-- <updater>Chirag\Stockproduct\Model\ResourceModel\Test\Newlistcollection</updater> -->
                        </argument>
                        <argument name="default_sort" xsi:type="string">id</argument>
                        <argument name="default_dir" xsi:type="string">DESC</argument>
                        <argument name="save_parameters_in_session" xsi:type="string">1</argument>

                        <!-- for filter condition -->
                        <argument name="default_filter" xsi:type="array">
                            <item name="emailstatus" xsi:type="string">1</item>
                        </argument>


                    </arguments>
                    <block class="Magento\Backend\Block\Widget\Grid\ColumnSet" name="stockproduct_all_grid.grid.columnSet" as="grid.columnSet">

                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="id">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">ID</argument>
                                <argument name="index" xsi:type="string">id</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="name">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">ProductId</argument>
                                <argument name="index" xsi:type="string">productid</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="productname">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Product Name</argument>
                                <argument name="index" xsi:type="string">productname</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="emailid">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Emailid</argument>
                                <argument name="index" xsi:type="string">emailid</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="emailstatus">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Emailstatus</argument>
                                <argument name="index" xsi:type="string">emailstatus</argument>
                                <argument name="type" xsi:type="string">text</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="created_at">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Created at</argument>
                                <argument name="index" xsi:type="string">created_at</argument>
                                <argument name="type" xsi:type="string">datetime</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="sentdate">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Sent date</argument>
                                <argument name="index" xsi:type="string">sentdate</argument>
                                <argument name="type" xsi:type="string">datetime</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                    </block>
                </block>
            <!-- </block> -->
        </referenceContainer>
    </body>
</page>

Filepath : Chirag\Stockproduct\Model\ResourceModel\Test\Newlistcollection.php

<?php
namespace Chirag\Stockproduct\Model\ResourceModel\Test;

class Newlistcollection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    /**
     * Define model & resource model
     */
    protected function _construct()
    {
        $this->_init(
            'Chirag\Stockproduct\Model\Test',
            'Chirag\Stockproduct\Model\ResourceModel\Test'
        );
        /*public function update($argument)
        {
            $argument->addFieldToFilter('emailstatus',array('eq' => '1'));
            return $argument;
        }*/

    }
}
?>

This code gives this result : enter image description here I want to display data with the condition (emailstatus == 1) from my custom table. Here all data display and total row are 15. But there are 3 rows which have emailstatus =0. So I want to display 12 rows instead of 15. All 3 rows do not display which has emailstatus=0.

If you want to more code, inform me. I will put it. Thanks in advance...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.