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

Listview Indexing Problem

2 Answers 34 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Matt Miller
Top achievements
Rank 1
Matt Miller asked on 23 Nov 2013, 03:16 PM

ListView Definition


 var carriers = $("#carrierList").kendoListView({
            dataSource: t94StragglerCarriers,
            selectable: true,
            pageable : true ,
            change: onChange,
            dataBound: onDataBound,
            dataBinding : onDataBinding ,
            template : kendo.template($("#carrierTemplate").html())
        }).data("kendoListView");

Template Definition

<script type="text/x-kendo-tmpl" id="carrierTemplate">
    <div id='carrierListVal' class='k-textbox'>#:val#</div>    
    <br/>
</script>

DataSource Definition

 var t94StragglerCarriers = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "/MenuTrain/T94StragglerCarriers",                    
                    dataType: "json"                   
                },
                schema: {
                    model: {
                        id: "id",                        
                        fields: {
                            id: {type : "string"} ,
                            val: {type : "string"}
                        }                        
                    }
                },               
                pageSize: 5,
                serverPaging : true 
            }
        });

I've tried several variations for the datasource. From not specifying the schema to just specifying the id.

OnChange Event Handler Definition

function onChange() {
            var listView = $("#carrierList").data("kendoListView");
            var index = listView.select().index();
            var item = listView.dataSource.view()[index];
            console.log("Item " + index + " selected. Text = " + item.id);
        }

Here is the json string returned from my controller's action method: 

[{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"CHTT"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"CMO "},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"CTCX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"DBUX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"GATX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"MWCX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"NDYX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"PLMX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TAEX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TCIX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TEIX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TILX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"UP  "},{"id":"ffbcdb6c-4d3a-45f6-8ef6-ada5f28ba44b","val":"MDXx"}]

The listview renders correctly. But it's as if the listview's select().index() methods are treating each field as an item. For example , the first object's id field is index 0, the first object's val field is index 1, and so on.


What am i doing wrong here?

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 26 Nov 2013, 03:19 PM
Hi Matt,

I posted a reply on this issue in the other thread which you opened:

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
Matt Miller
Top achievements
Rank 1
answered on 26 Nov 2013, 03:43 PM
Thanks for your help and patience. Eventually i will figure this stuff out.
Tags
ListView
Asked by
Matt Miller
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Matt Miller
Top achievements
Rank 1
Share this question
or