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

Button in ListView Template linked to ViewModel

2 Answers 372 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Huw Lloyd
Top achievements
Rank 1
Huw Lloyd asked on 11 Mar 2014, 03:36 AM
Hi,

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 Answers, 1 is accepted

Sort by
0
Huw Lloyd
Top achievements
Rank 1
answered on 12 Mar 2014, 09:16 AM
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: {
         model:
         {
             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?


0
Petyo
Telerik team
answered on 12 Mar 2014, 02:02 PM
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.

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