Button in ListView Template linked to ViewModel

3 posts, 0 answers
  1. Huw Lloyd
    Huw Lloyd avatar
    20 posts
    Member since:
    Jul 2009

    Posted 10 Mar 2014 Link to this post


    Been working a lot with Web components on a new project I am working on, now trying to develop a mobile app, so switching over to Kendo Mobile.

    I want to add a button to selected items in a ListView using a template, which I can do easily enough, and I have added data-bind attribute with a value of "click: onDelete". The button appears correctly in the items I want it to appear in.

    When a user clicks on the button I want to run the relevant code in my viewModel passing in the details of the item for which the button was clicked so I can do some further processing.

    How do I do this - is there any example somewhere of how this works because I am unable to get the button click to trigger a function call in my viewModel and pass in teh relevant item details

    Many thanks in advance

  2. Huw Lloyd
    Huw Lloyd avatar
    20 posts
    Member since:
    Jul 2009

    Posted 12 Mar 2014 in reply to Huw Lloyd Link to this post

    OK so I have made some progress in that I have added a detailbutton to my template and am able to trigger the click event for this which is a start...

    I use the code to pick the item ID which I can then use for my next stage

    var item = e.button.closest("li"); //get the item
    alert("ID= " + item.data("uid"));

    However the ID I receive is not the ID from my datasource, rather it is some randomly generated GUID I assume by the Kendo Framework.

    The schema part of my datasource code looks like this:

    schema: {
                 id: "ID"
             data: "List",
             errors: "APIError",
             total: "TotalRowCount"

    The data I am using is contained in List, and the name of the field that contains the ID is called ID, so why does it not set teh data-uid correctly to the value I require?

  3. Petyo
    Petyo avatar
    2444 posts

    Posted 12 Mar 2014 Link to this post

    Hi Huw,

    The corresponding data item is accessible in the data field of the button event handler parameter. Please check this example for what I mean.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top