Nest Rating in Listview

1 Answer 87 Views
ListView Rating Templates
CPS
Top achievements
Rank 1
Iron
Iron
CPS asked on 07 Dec 2022, 01:27 PM

Hello

I would like to use jQuery ListView to display products for an eshop solution.

Is it possible to nest a jQuery Rating Widget inside the ListView template and set the value when binding the data to the ListView?

I use ASP.Net Core with RazorPages.

Thank u for ur support!

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 12 Dec 2022, 07:09 AM

Hi Mirko,

It is possible to add a Kendo UI Rating inside the ListView template. Here are the steps:

 - Add an input to the template:

      <script type="text/x-kendo-template" id="template">
        <div class="product">
            <img src="../content/web/foods/#= ProductID #.jpg" alt="#: ProductName # image" />
            <h3>#:ProductName#</h3>
            <input id='rating_#=ProductID#' data-bind='value: SupplierID' class='rating'/>
        </div>
      </script>

 - Initialize the Rating and the binding for it inside the ListView dataBound event handler:

          dataBound: function() {
              var listView = this;
              $(this.content).find(".k-listview-item").each(function() {
                var dataItem = listView.dataItem(this);
                $(this).find(".rating").kendoRating({
                  min: 1,
                  max: 5,
                  label: false,
                  selection: "continuous"
                });
                kendo.bind($(this), dataItem);
              }) 
            }

Here is a runnable Dojo I prepared demonstrating the above:

Please let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ListView Rating Templates
Asked by
CPS
Top achievements
Rank 1
Iron
Iron
Answers by
Nikolay
Telerik team
Share this question
or