locked
When will custom datasource complete loading data?

    Question

  • I'm trying create my own datasource. I'm following the sample code.

    Basically, I dont know, how I will know the datasource has completed fetching data. Could any provide me a hint/sample?



    • Edited by spesalvi Tuesday, November 20, 2012 1:11 PM for clarity
    Tuesday, November 20, 2012 11:28 AM

Answers

  • In the sample u can do the following:

    1. Add a completionCallback into the constructor of bingImageSearchDataAdapter

    // Definition of the data adapter
    var bingImageSearchDataAdapter = WinJS.Class.define(
        function (devkey, query, completionCallback) {
    
            this._completionCallback = completionCallback;
    
            // Constructor
            this._minPageSize = 50;
            this._maxPageSize = 50;
            this._maxCount = 1000;
            this._devkey = devkey;
            this._query = query;
        },

    2. call the completionCallback in the getCount() function and call it just before count is returned:

    if (that._completionCallback)
        that._completionCallback()
    
    return count;

    3. Next, in scenario1.js, adjust the new'ing up of the bingImageSearchDataSource to this:

    //Create the bing itemDataSource
    var myDataSrc = new bingImageSearchDataSource.datasource(devkey, searchTerm, function completionCallback()
    {
        // hide the ring here
    });

    To sum it up, i've added a callback to the bingImageSearchDataAdapter and call it once the data is loaded. Then in the new'ing up of the datasource i've provided the actual implementation of the callback in where u can do your thing.

    Good luck!

    • Marked as answer by spesalvi Wednesday, November 21, 2012 10:51 AM
    Tuesday, November 20, 2012 4:33 PM

All replies

  • There are multiple controls to display progress...
    http://msdn.microsoft.com/en-us/library/windows/apps/hh465451.aspx#progress_controls

    Please check the guidelines for which progress control to be used in which scnario

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465469.aspx

    having said that, let's assume you want to use progress ring (indeterminate progress ring )......
    put a div tag in default.html file

    <div id="myprogressdiv">
            <progress id="myprogress" class="win-ring"></progress>
        </div>

    And then, in the method, which calls the service/gets data from datasource; put the below line as the first line:

    $("#myprogressdiv").show();

    And then, at then end of that method, after the call for the data has been made, put the below line:


    $("#myprogressdiv").hide();

    Hope this helps


    Arindam Basu


    Tuesday, November 20, 2012 12:56 PM
  • My question not about showing progress control. I want to know when, the custom data source will complete loading data, so that I have hide my progress control. 
    • Edited by spesalvi Tuesday, November 20, 2012 1:07 PM
    Tuesday, November 20, 2012 1:07 PM
  • I would also like  to know, if the custom data handler will return any promise.  Then showing/hiding progress control is not a problem.


    • Edited by spesalvi Tuesday, November 20, 2012 1:14 PM
    Tuesday, November 20, 2012 1:13 PM
  • In the sample u can do the following:

    1. Add a completionCallback into the constructor of bingImageSearchDataAdapter

    // Definition of the data adapter
    var bingImageSearchDataAdapter = WinJS.Class.define(
        function (devkey, query, completionCallback) {
    
            this._completionCallback = completionCallback;
    
            // Constructor
            this._minPageSize = 50;
            this._maxPageSize = 50;
            this._maxCount = 1000;
            this._devkey = devkey;
            this._query = query;
        },

    2. call the completionCallback in the getCount() function and call it just before count is returned:

    if (that._completionCallback)
        that._completionCallback()
    
    return count;

    3. Next, in scenario1.js, adjust the new'ing up of the bingImageSearchDataSource to this:

    //Create the bing itemDataSource
    var myDataSrc = new bingImageSearchDataSource.datasource(devkey, searchTerm, function completionCallback()
    {
        // hide the ring here
    });

    To sum it up, i've added a callback to the bingImageSearchDataAdapter and call it once the data is loaded. Then in the new'ing up of the datasource i've provided the actual implementation of the callback in where u can do your thing.

    Good luck!

    • Marked as answer by spesalvi Wednesday, November 21, 2012 10:51 AM
    Tuesday, November 20, 2012 4:33 PM