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

Want to be able to get the item selected on the 'change' event in a ListView

2 Answers 634 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 26 Jul 2012, 04:31 PM
I'm using MVC, so the following example:

http://www.kendoui.com/blogs/teamblog/posts/12-04-12/an_in-depth_look_at_the_listview.aspx

Doesn't really help me because i don't have a 'datasource' object in javascript.  What can i use in a simliar fashion for MVC?  I have the following so far
function onchange(e) {
       var lst = $("#lstLPG").data("kendoListView");
   }
but i don't know how to get the selected object from either the 'e' or 'lst' object.

2 Answers, 1 is accepted

Sort by
0
Phil
Top achievements
Rank 1
answered on 10 Aug 2012, 10:55 PM
ended up having to fix this myself.  Not sure why this isn't easier to find:

var ds = $("#lstHigh").data("kendoListView");
        var index = ds.select().index(),
                    dataItem = ds.dataSource.view()[index];
0
Michael
Top achievements
Rank 1
answered on 20 Aug 2012, 05:09 PM
You could just respond with the controller via an ActionResult. 
From the Controller... (Added the second action to handle just the selection...)

@model IEnumerable<Kendo.Mvc.Examples.Models.ProductViewModel> 
@(
Html.Kendo().ListView<Kendo.Mvc.Examples.Models.ProductViewModel>(Model)     
.Name("listView")     
.TagName("div")     
.ClientTemplateId("template")     
.DataSource(dataSource => {         
dataSource.Read(read => read.Action("Products_Read""ListView"));         
dataSource.PageSize(12);     
})     
.Pageable()             
.Selectable(selectable => selectable.Mode(ListViewSelectionMode.Multiple))     
.Events(events => events.Change("onChange").DataBound("onDataBound")) )



namespace Kendo.Mvc.Examples.Controllers {     
public partial class ListViewController : Controller     
{         
public ActionResult Index()         
{             
return View(GetProducts());         
}                                                
public ActionResult Products_Read([DataSourceRequestDataSourceRequest request)         
{             
return Json(GetProducts().ToDataSourceResult(request));         
}         
private static IEnumerable<ProductViewModel> GetProducts()         
{             
var northwind = new NorthwindDataContext();             
return northwind.Products.Select(product => new ProductViewModel             
{                 
ProductID = product.ProductID,                 
ProductName = product.ProductName,                 
UnitPrice = product.UnitPrice ?? 0,                 
UnitsInStock = product.UnitsInStock ?? 0,                 
UnitsOnOrder = product.UnitsOnOrder ?? 0,                 
Discontinued = product.Discontinued,                 
LastSupply = DateTime.Today             
});         
}     
}
}

public partial class ListViewController : Controller     
{         
public ActionResult Selection()         
{             
return View(GetProducts());         
}             
}
Tags
ListView
Asked by
Phil
Top achievements
Rank 1
Answers by
Phil
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or