4

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.

  • you can get the rating value from PDP page ..just use this logic – Pramod Jan 3 at 9:36
  • What is PDP page? Can you please explain it?Thank you – Keval Kadia Jan 3 at 10:05
  • by default rating is available on PRODUCT DETAIL PAGE from there you can the value of ratings – Pramod Jan 3 at 10:06
  • Its a custom module and i am storing data into my custom table. On bases of the data stored in db, i want to display star rating as shown above.Currently its displaying 1 to 5 as output. – Keval Kadia Jan 3 at 10:10
2

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>

| improve this answer | |

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.