Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

When we want to paginate the results in our gadget template, we use the multidatasource approach that allow us to perform some server transformation like limit, group, select, param, where, …

In our sample, we can get the data page by page with the following instruction:

vm.from("{{datasource}}").skip(step*bulk).limit(bulk).exec().then

Now we can iterate through the results with, for example, the recursive async function iterateResult. It’s necessary to call first with the inicial params:

vm.acum = [];
var bulk = 1000;
var step = 0;
iterateResult(vm.acum, step, bulk, callback);

The callback function will be call when all the data have been recovered:

//function for doing something after all records are recover
function callback(){
   alert("Recovered " + vm.acum.length + " records") 
}

The full code of the example is the following:

//recurse async function for recovering data. When all data is processed callback function is called
function iterateResult(acum,step,bulk,callback){
    var acum = acum;
    var step = step;
    var bulk = bulk;
    var callback = callback;
    //salesimportonto_raw is the datasource
     vm.from("salesimportonto_raw").skip(step*bulk).limit(bulk).exec().then(
         function(data){
             if(data!=null && data.length>0){//there is more data
                acum.push.apply(acum, data);
                step++;
                iterateResult(acum,step,bulk,callback);
             }
             else{//there isn't more data
                 //Paginate finished, now draw chart or other things
                 callback()
             }
         }
     )
}

//function for doing something after all records are recover
function callback(){
   alert("Recovered " + vm.acum.length + " records") 
}

//This function will be call once to init components
vm.initLiveComponent = function(){
    vm.acum = [];
    var bulk = 1000;
    var step = 0;
    iterateResult(vm.acum, step, bulk, callback);
    //Here we don't have the result because async function
};

  • No labels