1. #51
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    caretta is on a distinguished road

      0  

    Default


    i never try that but i try to override store.totalCount property with a transaction "Select count(*)" but i cant do this : )

  2. #52
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    57
    shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough

      0  

    Default


    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().

  3. #53
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    caretta is on a distinguished road

      0  

    Default


    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

  4. #54
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    57
    shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough

      0  

    Default


    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);
          }
        },

  5. #55
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    caretta is on a distinguished road

      0  

    Default


    i use that but store.totalCount is giving undefined still.

  6. #56
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    57
    shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough

      0  

    Default


    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()

  7. #57
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    57
    shepsii is a jewel in the rough shepsii is a jewel in the rough shepsii is a jewel in the rough

      0  

    Default


    Quote Originally Posted by shepsii View Post
    I'm still baffled but some progress!

    Whether or not the dom exception 18 is raised is entirely dependent on the name of the database.

    For some reason, on my machine, any app I try to build where the database name is "sqlitedemo", I have no issues whatsoever. Any other name and it raises the exception.

    No idea why; there's no difference between sqlitedemo and any other database names, completely baffles me.
    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

  8. #58
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    caretta is on a distinguished road

      0  

    Default


    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:

    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);    },
    And also i add the total count function;

    Code:
        /* 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);          },
    this works good also ty to u, shepsii

  9. #59
    Sencha User
    Join Date
    May 2012
    Location
    Glasgow, UK
    Posts
    17
    Vote Rating
    0
    henry.wilson is on a distinguished road

      0  

    Default


    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 ):
    Code:
    Ext.define('Navis.model.Claim', {
        extend: 'Ext.data.Model',
    
        config: {
            fields: [
                ...
                ],
            proxy: {
                        type: 'sqlitestorage',
                        dbConfig: {
                            tablename: 'claims',
                            dbConn: Navis.util.InitSQLite.getConnection()
                        }
                }
        }
    });
    SyncStore (pulls from Web Service)
    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'
                        }
                    }
                }
    });
    Local store (should retrieve from SQLite DB but doesn't)
    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
        }
    });
    function to sync data:
    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();
        }

  10. #60
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    caretta is on a distinguished road

      0  

    Default


    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();        });