i never try that but i try to override store.totalCount property with a transaction "Select count(*)" but i cant do this : )
Printable View
i never try that but i try to override store.totalCount property with a transaction "Select count(*)" but i cant do this : )
The transaction would only produce a result on the callback anyway so that's unlikely to be of any use. Could you post some more code? I'm not familiar with the listpaging plugin.
You are correct that the _totalCount property is only ever 0. Let me look into how localstorage deals with this. I see there's a distinction between _totalCount and getCount().
listpaging plugin works with store.totalCount and the getCount parameters. If store.totalCount property comes 0 than listpaging shows that "No More Records" because of totalCount=0.
http://docs.sencha.com/touch/2-0/#!/...gin.ListPaging
Ok really easy fix for you that I will update on github asap.
Override the applyData function of the SqliteStorage.js file to this:
Code:applyData: function(data, operation, callback, scope) {
var me = this;
operation.setResultSet(Ext.create('Ext.data.ResultSet', {
records: data,
total : data.length,
loaded : true
}));
// finish with callback
operation.setRecords(data);
operation.setSuccessful();
operation.setCompleted();
if (typeof callback == "function") {
callback.call(scope || me, operation);
}
},
i use that but store.totalCount is giving undefined still.
ok I need more of your code then because with the proxy set as that, with the demo app, I can use Ext.getStore('People').getTotalCount() to see the correct number in the store.
Note that store.totalCount shouldn't be anything. store._totalCount is where sencha touch puts the data in memory, but that value should always be accessed using store.getTotalCount()
Ok so back to this...
I have to everytime use 'sqlitedemo' as my database name and then do a find and replace on the generated file.
I need to understand more about the scope that javascript is running from sencha command to get what's going on. It would make sense that it's only when the database doesn't yet exist - but in which scope is the javascript running and where would it be looking for the sqlite database? How would the database have been created in the first place? grrr
i have override some functions for listpagging plugin fix; because store.getTotalCount must return "Total Row Number". Not paged row number. store.getCount() returning paged row number.
So i override these functions:
And also i add the total count function;Code:applyData: function(data, operation, callback, scope, totalcount) { var me = this;
operation.setResultSet(Ext.create('Ext.data.ResultSet', { records: data, total : totalcount, /* changed for listpaging plugin */ loaded : true })); // finish with callback operation.setRecords(data); operation.setSuccessful(); operation.setCompleted(); if (typeof callback == "function") { callback.call(scope || me, operation); } }, applyDataToModel: function(tx, results, operation, callback, scope) { var me = this, Model = me.getModel(), fields = Model.getFields().items; var records = me.parseData(tx, results); var storedatas = []; if (results.rows && records.length) { for (i = 0; i < results.rows.length; i++) { var rowid = records[i].rowid; var record = {}; Ext.each(fields, function(f) { if (f.getType().type.toUpperCase() == 'AUTO') { record[f.getName()] = Ext.decode(Ext.isDefined(records[i][f.getName()]) ? records[i][f.getName()] : null); } else { record[f.getName()] = Ext.isDefined(records[i][f.getName()]) ? records[i][f.getName()] : null; } }); storedatas.push(new Model(record, rowid)); } }
/* changed for listpaging plugin */ me.getTotalRowCount(storedatas, operation, callback, scope); },
this works good :) also ty to u, shepsiiCode:/* added for listpaging plugin */ getTotalRowCount: function(storedatas, operation, callback, scope) { var me = this var onSuccess, onError; onSuccess = function(tx, results) { var totalcount=results.rows.item(0).Co; me.applyData(storedatas, operation, callback, scope, totalcount); };
onError = function(tx, err) { me.applyData(storedatas, operation, callback, scope, 0); me.throwDbError(tx, err); };
me.transactionDB(me.getDb(), [function(tx) { tx.executeSql("SELECT COUNT(*) AS Co FROM "+me.getDbConfig().tablename, [], onSuccess, onError); }], null, null); },
I'm having issues with actually reading the data back out of the SQLite DB, I suspect I'm missing something obvious cos I'm fairly new to Sencha Touch so apologies if that's the case...
My app is designed to Grab data from a web service, then store it locally for persistence in the SQLite DB. So I've got a SyncStore to grab the data from the Web Service, and a local store to save it into the DB. I can see the data getting saved into the DB (I can query it using SQLiteStudio) but it's not coming back out into the app. Code snippets follow.
Model Object (with proxy to save into SQLLite DB ):
SyncStore (pulls from Web Service)Code:Ext.define('Navis.model.Claim', {
extend: 'Ext.data.Model',
config: {
fields: [
...
],
proxy: {
type: 'sqlitestorage',
dbConfig: {
tablename: 'claims',
dbConn: Navis.util.InitSQLite.getConnection()
}
}
}
});
Local store (should retrieve from SQLite DB but doesn't)Code:Ext.define('Navis.store.ClaimsSync', {
extend: 'Ext.data.Store',
requires: ['Navis.model.Claim'],
config: {
model: 'Navis.model.Claim',
proxy: {
type: 'ajax',
url: 'http://localhost/naviswebservice/syncservice.svc/GetClaimsData',
reader : {
type : 'json',
model: 'Navis.model.Claim'
}
}
}
});
function to sync data:Code:Ext.define('Navis.store.Claims', {
extend: 'Ext.data.Store',
requires: ['Navis.model.Claim'],
config: {
model: 'Navis.model.Claim',
autoLoad: true,
storeId: 'Claims',
pageSize: 1000
}
});
Code:syncData: function(){
//get stores
var claimStore = Ext.getStore('Claims');
var claimSyncStore = Ext.getStore('ClaimsSync');
//clear local store
console.log('Sync: Clearing Local Datastore');
claimStore.removeAll(true);
//set handler on main store, when sync is done disabled masking
claimStore.on('load', function() {
Ext.Viewport.setMasked(false);
console.log('Sync: Finished!');
});
//set handler on sync store, when load from web service is done, save every record locally
claimSyncStore.on('load', function() {
console.log('Sync: Saving data to local DB');
claimSyncStore.each(function(record){
record.save();
});
claimStore.load();
});
//enable mask
Ext.Viewport.setMasked({
xtype: 'loadmask',
message: 'Syncing data, please wait...'
});
console.log('Sync: Retrieving Data from Web Service');
//load from web service
claimSyncStore.load();
}
i think that you must use 2 diffrent model. One for offline mod one for online sync.
Code:claimSyncStore.on('load', function() { console.log('Sync: Saving data to local DB'); claimSyncStore.each(function(record){ var newRec=Ext.create('Navis.model.Claim'); newRec.set(record.getData); Ext.getStore('claimStore').add(newRec); }); claimStore.sync(); claimStore.load(); });