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

Data source data

1 Answer 719 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Andres
Top achievements
Rank 1
Andres asked on 29 May 2012, 06:35 PM
I have a datasource, and i need to get the first element, and save it into a variable.
The methods get(x) and at(x), doesn't work. How can i do this?

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 30 May 2012, 08:16 AM
Hello Andres,

In order to retrieve the dataSource records you can use the data or view methods. The first item you can get by its index ( dataSource.data()[0] / dataSource.view()[0] ) or by using the at method ( dataSource.at(0) ).

If those approaches does not work, the reason might be the dataSource does not contain any records ( e.g. the dataSource.data() returns empty array [ ] ). Most likely that will happen if:
  • the read action was not invoked ( dataSource.read() )
  • the asynchronous Ajax request is not finished at the time when you try to get the first item - that is why I recommend to hook up to the change event.
  • the data of the schema is not defined or does not point to the element that contains the data array.

All the best,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Andres
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or