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

dataSource: ds vs dataSource: { data: ds }

2 Answers 213 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Umer
Top achievements
Rank 1
Umer asked on 17 Apr 2013, 06:15 AM
Hi Everyone,

I have following very simple code that works as expected.

        $(document).ready(function () {
 
            var ds = null;
 
            ds = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "data.json", dataType: "json"
                    }
                },
                change: function () {
                    var data = this.data(); // or this.view();
                }
 
            });
 
 
            $("#grid").kendoGrid({
 
                dataSource: ds,
 
//                      dataSource: {
//                          data: ds,
//                          pageSize: 2
//                      },
 
                sortable: {
                    mode: "single",
                    allowUnsort: false
                },
 
                columns: [
                    {
                        field: "Product",
                        title: "Product Title"
                    },
                    {
                        field: "Manufacturer",
                        title: "Manufacturer Title"
                    },
                    {
                        field: "Description",
                        title: "Description Title"
                    },
                    {
                        field: "Property2",
                        title: "Property 2"
                    }
                ]
            });
 
 
        });
Why do I not need to call ds.read() in this scenario?

And 

If i replace the dataSource: ds with the commented block dataSource: {data: ds } no data is displayed at all. Any idea why?

Thanks for the help.

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 17 Apr 2013, 07:27 AM
Hello Umer,

Quoted by documentation:
"
The data source of the widget which is used render table rows. Can be a JavaScript object which represents a valid data source configuration, a JavaScript array or an existingkendo.data.DataSource instance.

If the dataSource option is set to a JavaScript object or array the widget will initialize a new kendo.data.DataSource instance using that value as data source configuration.

If the dataSource option is an existing kendo.data.DataSource instance the widget will use that instance and will not initialize a new one.

"

Above description and examples/in the help article/ explains the difference between possible the configuration settings.

To your question "Why do I not need to call ds.read() in this scenario?"
 - The Grid widget will automatically call read of its data source, except when autoBind: false is set.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Umer
Top achievements
Rank 1
answered on 17 Apr 2013, 07:56 AM
Thanks Nikolay. 
Tags
Data Source
Asked by
Umer
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Umer
Top achievements
Rank 1
Share this question
or