How to display star rating into my custom customer feedback grid view using renderer in magento 2?

magento.stackexchange https://magento.stackexchange.com/questions/300266

  •  28-03-2021
  •  | 
  •  

문제

This is my listing.xml code for rating . I want to display star rating to the custom feedback grid.

<column name="rating">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                <item name="label" xsi:type="string" translate="true">Rating</item>
            </item>
        </argument>
    </column>

I want Something like this

I want something like this.

도움이 되었습니까?

해결책

I got the answer. I create class for rating.php in ui->component->Listing->column and displayed value in rating.html file in view->adminhtml->web->tamplate. That worked for me. I will now return css class and add it to my html code to make it look bit better.Thank you all for you helping. If there is better way let me know.

rating.php

public function prepareDataSource(array $dataSource)
{
    if(isset($dataSource['data']['items'])){
        foreach($dataSource['data']['items'] as &$item){
            if($item['rating']){
                $data = [];
                for($i = 0; $i < 5; $i++)
                    if($i < $item['rating'])
                        $data[] = 'selected';
                    else
                        $data[] = 'notSelected';

                $item['rating'] = $data;
            }
        }
    }
    return parent::prepareDataSource($dataSource); // TODO: Change the autogenerated stub
}

rating.html

<div class="field required review-field-ratings">
<div class="control review-control-vote" >
    <!--  ko foreach: $col.getLabel($row())   -->
    <!-- ko if: $data == "selected"-->
    <span style="color: rgb(51, 51, 51);">★</span>
    <!--/ko-->
    <!-- ko if: $data != "selected"-->
    <span style="color: rgb(204, 204, 204);">★</span>
    <!--/ko-->
    <!--    /ko    -->
</div>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top