dimanche 13 avril 2014

Large data not sync on Store for Ajax call

Hi i have this method that get records from the server with paging that loop till all the records has been loaded to the store which good. But when i tried to execute same method lets say 5 times, close and open the app. I saw the data is not really sync to the store so i got always an infinite loop.

I have same method for this on 2 stores that has more than 3000+ records.


Please i really need help! Thanks and Regards.


Below is my code:


Call Sync Method:



Code:



//Load Defect Local Stores
var defectsLocalStore = Ext.getStore('DefectMatrix');
defectsLocalStore.clearFilter();
defectsLocalStore.load();
defectsLocalStore.sync();


Test.util.Proxy.checkConnection(function () {
console.log('getting total defects count');
me.getDefectTotalRows(function (totalRow) {
console.log('total defect count is:' + totalRow + 'total local defect: ' + defectsLocalStore.getData().length);


if (defectsLocalStore.getData().length == 0 || defectsLocalStore.getData().length < totalRow) {


console.log('remove first all defects data');


var decMatrix = Ext.getStore('DefectMatrix');
decMatrix.clearFilter();
decMatrix.getProxy().clear();
decMatrix.removeAll();
decMatrix.load();
decMatrix.sync();




console.log('bacth load all defects');
me.defectSync(0, totalRow, function (data) {
if (data == 0) {
Test.util.Proxy.showAlertNotification('ALERT!', 'Slow connection detected! Please try again.',
function () {
console.log('defects store is loaded with:' + defectsLocalStore.getData().length);
Ext.Viewport.setMasked(false);
task.cancel();
});
} else {
console.log('defects store is loaded with:' + defectsLocalStore.getData().length);
Ext.Viewport.setMasked(false);
task.cancel();
}
});
}
else {
console.log('update last modified defects');
me.loadUpdatedDefects(function (data) {
if (data == 0) {
Test.util.Proxy.showAlertNotification('ALERT!', 'Slow connection detected! Please try again.',
function () {
console.log('defects store is loaded with:' + defectsLocalStore.getData().length);
Ext.Viewport.setMasked(false);
task.cancel();
});
} else {
console.log('defects store is loaded with:' + defectsLocalStore.getData().length);
Ext.Viewport.setMasked(false);
task.cancel();
}
});
}
});
},
function () {
Test.util.Proxy.showAlertNotification('ALERT!', 'Slow connection detected!Please try again.',
function () {
console.log('No network detectd clear defects data');
defectsLocalStore.load();
//Load all local Stores
Ext.Viewport.setMasked(false);
task.cancel();
});
});

Sync Batch update Method:



Code:



defectSync: function (counter, totRecords, callback) {
var me = this;
if (counter == undefined)
counter = 0;


//load defect matrix local local storage
var defectsLocalStore = Ext.getStore('DefectMatrix');
defectsLocalStore.clearFilter();
defectsLocalStore.load();
defectsLocalStore.sync();


console.log("Defects Number loaded:" + counter + 'and on store before ajax call:' + defectsLocalStore.getData().length);






Test.util.Proxy.checkConnection(function () {


var defectssurl = 'http://ift.tt/1ezLZOC' + counter;
Test.util.Proxy.doAjaxCall(defectssurl, '',
function (response) {


var data = Ext.JSON.decode(response.responseText); //encode Json List


Ext.Array.each(data, function (record) {
counter++;

defectsLocalStore.add(record);
});




defectsLocalStore.sync(); // The magic! This command persists the records in the store to the browsers localStorage


//Check if all records loaded on local storage is equail to total defect rows then complete
if (defectsLocalStore.getData().length >= totRecords) {
console.log('defect loading successfull');
callback();
} else {
console.log("Defects Number loaded:" + counter + 'and on store after sync:' + defectsLocalStore.getData().length);
//Trigger again until condition is met
me.defectSync(counter, totRecords, callback);
}
},
function (response) {
defectsLocalStore.load();
callback(0);
});
}
, function () {
defectsLocalStore.load();
callback(0);
});


}




Aucun commentaire:

Enregistrer un commentaire