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

3 posts, 0 answers
  1. Phil
    Phil avatar
    30 posts
    Member since:
    Aug 2012

    Posted 26 Jul 2012 Link to this post

    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. Phil
    Phil avatar
    30 posts
    Member since:
    Aug 2012

    Posted 10 Aug 2012 Link to this post

    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];
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Michael
    Michael avatar
    8 posts
    Member since:
    Apr 2012

    Posted 20 Aug 2012 Link to this post

    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());         
    }             
    }
Back to Top