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

How to select??

2 Answers 141 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 27 Feb 2013, 01:13 AM
The kendo listview documentation says that you can pass in a selector or an array.  An array of what?

I have a complex kendo grid that is using inline custom editors based on information in the row.  This all works great, EXCEPT for the listview I'm adding.

Given something like this (I'm using underscore js by the way), how do I select the list items using javascript?

function createListViewEditor(container, options) {
        var list = _.find(_viewModel.model.LookupListCollection, function(x) {
            return (x.Id == options.model.StagingControlStageAttributeLookupCollectionId);
        });
 
        var listItems = [];
 
        _.forEach(list.LookupValues, function(x) {
            listItems.push({ text: x.CustomName, value: x.Id });
        });
 
        var lvSource = new kendo.data.DataSource({
            data: listItems
        });
 
        var listView = $('<div />')
            .appendTo(container)
            .kendoListView({
                dataSource: lvSource,
                selectable: "multiple",
                template: kendo.template($('#multiselecttemplate').html())
                 
            }).data("kendoListView");
 
        var indices = multiListSelectionHelper(listView.dataSource.data(), options.model.AttributeFieldValue.split(','));
 
        listView.select(indices);
 
        listView.bind("change", function(e) {
            var data = e.sender.dataSource.view(),
                selected = $.map(e.sender.select(), function(item) {
                    return data[$(item).index()].value;
                });
 
            options.model.AttributeFieldValue = selected.join();
        });
    }
     
    function multiListSelectionHelper(options, current) {
        var items = [];
        _.forEach(options, function (x) {
            _.forEach(current, function(y) {
                if (x.value == parseInt(y)) {
                    items.push(x);
                }
            });
        });
 
        return items;
    }

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 28 Feb 2013, 03:16 PM
Hello Phil,

Basically the select method accepts either HTML element or array of HTML elements (or jQuery wrapped HTML element i.e. $('#someItem').

You cannot pass index of an element or the model ID.

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Phil
Top achievements
Rank 1
answered on 28 Feb 2013, 10:10 PM
Thanks for the info, the array of $("#someitem) worked perfect.
Tags
ListView
Asked by
Phil
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Phil
Top achievements
Rank 1
Share this question
or