0

I am showing my custom modules grid in magento2 admin and that is showing fine with some filter options. In the start, I have only two status of the row - "New & Canceled" that was showing right in the grid column. Today I added some more statuses like - "Completed, Rescheduled".
Via forms respective row data updating successfully, but in grid view its showing wrong, always showing "New".

Here is my code in

app/code/NameSpace/Module/view/adminhtml/ui_component/booking_booking_listing.xml

<column name="status" >
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Namespace\MyModule\Model\Booking\Source\IsActive</item>
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">select</item>
            <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
            <item name="dataType" xsi:type="string">select</item>
            <item name="label" xsi:type="string" translate="true">Status</item>
            <item name="sortOrder" xsi:type="number">8</item>
        </item>
    </argument>
</column>

Namespace\MyModule\Model\Booking\Source\IsActive.php

namespace Namespace\MyModule\Model\Booking\Source;

use Namespace\MyModule\Model\Booking;
use Magento\Framework\Data\OptionSourceInterface;

    class IsActive implements OptionSourceInterface
    {
        protected $booking;

        public function __construct(Booking $booking)
        {
            $this->booking = $booking;
        }

        public function toOptionArray()
        {
            $options[] = ['label' => '', 'value' => ''];
            $availableOptions = $this->booking->getAvailableStatuses();
            foreach ($availableOptions as $key => $value) {
                $options[] = [
                    'label' => $value->getText(),
                    'value' => $key,
                ];
            }
            return $options;
        }
    }

Returning array is -

Array
(
    [0] => Array([label] => [value] => )
    [1] => Array([label] => New [value] => 1)
    [2] => Array([label] => Rescheduled [value] => 2)
    [3] => Array([label] => Completed [value] => 3)
    [4] => Array([label] => Canceled [value] => 0)
    [5] => Array([label] => Did not show up [value] => 4)
)

In admin grid filter its showing right options and filtering also right as per datbase values.

But In grid its not showing right label.

Here is the Grid screenshot -

enter image description here

Please check and let me know what I am doing wrong.

Thanks

1 Answer 1

0

try below code:

namespace Namespace\MyModule\Model\Booking\Source;

use Namespace\MyModule\Model\Booking;
use Magento\Framework\Data\OptionSourceInterface;

class IsActive implements OptionSourceInterface
{
    protected $booking;

    public function __construct(Booking $booking)
    {
        $this->booking = $booking;
    }

    public function toOptionArray()
    {
        $availableOptions = $this->booking->getAvailableStatuses();
        foreach ($availableOptions as $key => $value) {
            $options[] = array('label' => $value->getText(),'value' => $key);
        }
        return $options;
    }
}
1
  • Thank you but solution not working ..
    – Atul
    Commented Aug 16, 2018 at 7:41

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.