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

Fetch does not update the data object??? Purpose?

2 Answers 136 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 04 Sep 2012, 03:51 PM
Hi All,

I am attempting to use Fetch in a change event for a combobox to update another combobox. Read works fine for the 2nd combobox's collection but when using fetch the data object for the second datasource does NOT update.

$("#comboOne").width(180).kendoComboBox({
        autoBind: false,
        dataTextField: "Name",
        dataValueField: "Id",
        dataSource: dsComboOne,
        change: function (e) {
            //dsComboTwo.read();
            dsComboTwo.fetch(function () {
                if (dsComboOne.total() == 0) {
                    //do stuff to DOM
                } else {
                    //do different stuff to DOM
                }
            });

            $("#comboTwo").data("kendoComboBox").value(null);
            $("#comboTwo").data("kendoComboBox").enable(true);
        }
    });


So calling dsComboTwo.read() works as expected. Calling dsComboTwo.fetch() does not actually update the dsComboTwo.data object. When i run a watch and break in the callback i can see the dsComboTwo.data is the same as the previous/initial call.

Is there some other way to do this? Callback on the datasource i am missing? The success: callback in the DS also does not seem to work. No error.. just does not fire. Same with the change: . Can someone clarify this with an example? I've seen variations of this question elsewhere.

2 Answers, 1 is accepted

Sort by
0
N Mackay
Top achievements
Rank 1
answered on 05 Sep 2012, 02:04 PM
You can do a callback on the fetch, don't know if this helps

var MyDataSource = new kendo.data.DataSource({
                    type: "odata",
                    transport: {
                        read: {
                            url: "http://MyServer/MyserWCFService.svc/MyEntity",
                            dataType: 'jsonp',
                            jsonpCallback: 'MyCallback'
                        }
                    }
     
            });
             
        if (sessionStorage.getItem('CustomerFilter'))
            {
            MyDataSource .filter({
                filters: [
                  { field: "CustName", operator: "startswith", value: sessionStorage.getItem('CustomerFilter') }
                ]
            });
            MyDataSource.fetch(fetchCallback);
            }
 
function fetchCallback() {
             
            if (MyDataSource.total() > 0)

The Callback added to the URL isn't the one that triggers when you do a fetch, you can specify one there so one isn't automatically generated which can cause performance issues.

You can also specify a callback when defining the Datasource, can't remember of the top of my head.

Total will return 0 if your using server paging.

Don't know if this is of any help.
0
N Mackay
Top achievements
Rank 1
answered on 05 Sep 2012, 02:05 PM
You can do a callback on the fetch, don't know if this helps

var MyDataSource = new kendo.data.DataSource({
                    type: "odata",
                    transport: {
                        read: {
                            url: "http://MyServer/MyserWCFService.svc/MyEntity",
                            dataType: 'jsonp',
                            jsonpCallback: 'MyCallback'
                        }
                    }
     
            });
             
        if (sessionStorage.getItem('CustomerFilter'))
            {
            MyDataSource .filter({
                filters: [
                  { field: "CustName", operator: "startswith", value: sessionStorage.getItem('CustomerFilter') }
                ]
            });
            MyDataSource.fetch(fetchCallback);
            }
 
function fetchCallback() {
             
            if (MyDataSource.total() > 0)

The Callback added to the URL isn't the one that triggers when you do a fetch, you can specify one there so one isn't automatically generated which can cause performance issues.

You can also specify a callback when defining the Datasource, can't remember of the top of my head.

Total will return 0 if your using server paging.

Tags
Data Source
Asked by
Rich
Top achievements
Rank 1
Answers by
N Mackay
Top achievements
Rank 1
Share this question
or