This is a migrated thread and some comments may be shown as answers.

ListView on Change, get "primary key" for selected item

1 Answer 243 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jillian
Top achievements
Rank 1
Jillian asked on 25 Jul 2013, 07:22 PM
I have a list view that has a change event.  When an item in my list view is selected how can I get the "key" that i set for the item instead of the text displayed?

<script type="text/x-kendo-tmpl" id="ItemTemplate">
  <div style="margin:5px;">
    #:ItemNo# - #:Description#<br />
  </div>
</script>
<%: Html.Kendo().ListView<ItemList>()
.Name("Items")<br>  .TagName("div"
 .DataSource(ds =>
     ds.Read(read => read.Action("ItemListRead", "Home"))
       .Model(m => m.Id(i => i.ItemKey)))
 .ClientTemplateId("ProjectItemTemplate")
 .Selectable(s => s.Mode(ListViewSelectionMode.Single))
 .Events(events => events.Change("onChange"))
%>

<script type="text/javascript">
   function onProjectItemChange(e) {
      var selected = $.map(this.select(), function (item) {
         return $(item).text();
      });
   }
</script>


1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 29 Jul 2013, 08:10 AM
Hello Jillian,


To achieve this you could get the uid of the selected item through the data-uid attribute and use the getByUid method of the DataSource to retrieve the model for it.
E.g.
function onChange(arg) {
    var selected = this.select();
    var model = this.dataSource.getByUid(selected.attr("data-uid"));
}

I hope that this was the information that you were looking for. I wish you a great day!

 

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ListView
Asked by
Jillian
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or