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

3 posts, 0 answers
  1. Rich
    Rich avatar
    65 posts
    Member since:
    Jul 2012

    Posted 04 Sep 2012 Link to this post

    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. N Mackay
    N Mackay avatar
    228 posts
    Member since:
    Dec 2010

    Posted 05 Sep 2012 Link to this post

    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.
  3. Kendo UI is VS 2017 Ready
  4. N Mackay
    N Mackay avatar
    228 posts
    Member since:
    Dec 2010

    Posted 05 Sep 2012 Link to this post

    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.

Back to Top