Results 1 to 4 of 4

Thread: Dataview wont update correctly if store has been emptied

  1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    4
    Answers
    1

    Default Dataview wont update correctly if store has been emptied

    I have the following store code:

    Code:
    Ext.define('AFA.store.requests', {
        extend: 'Ext.data.Store',
        config : {
            model   : 'AFA.model.request',
            storeId : 'requests',
            sorters : [
                {
                    property : 'counter',
                    direction : 'DESC'
                }
            ]
        }
    });
    
    
    Ext.define('AFA.model.request', {
        extend: 'Ext.data.Model',
        config : {
            fields : [
                {name: 'id', type: 'string'},
                {name : 'sender'},
                {name : 'response', defaultValue : []},
                {name : 'item', defaultValue : null},
                {name : 'active'}
            ],
            identifier: {
                type: 'uuid'
            }
        }
    });
    
    
    Ext.define('AFA.view.request', {
        extend  : 'Ext.dataview.component.DataItem',
        xtype   : 'request',
        config  : {
            height  : 250,
            width   : '100%',
            layout  : 'card',
            items : [
                {
                    height  : 120,
                    xtype   : 'container',
                    layout  : 'vbox',
                    width   : '100%',
                }
            ]
        }
    });
    
    
    Ext.define('AFA.view.requests', {
        extend: 'Ext.dataview.DataView',
        xtype : 'request-list',
        config: {
            xtype           : 'list',
            width           : '100%',
            height          : 250,
            store           : 'requests',
            variableHeights : false,
            useComponents   : true,
            defaultType     : 'request',
            emptyText       : '<div class="afa-empty"></div>',
            deferEmptyText  : false
        }
    });
    the data model is not asynchronous, hence there is no proxy defined in the config. the dataitem is in fact in a card layout as i have a summary and (optional depending on model data) detail view for each item.

    When I add new items to the store works fine and updates the dataview fine except for in one scenario. If i add one record to the store and then remove that, when i add a new item to the store the first (deleted) item appears in the dataview. The data view updates fine whenever i keep more than one item in the store. It also works fine if i keep a 'dummy' model instance in the store to make sure it never completely empties but this is obviously a hack not a solution. I can see the contents of the store in the console and the store definately contains just the new record, not the old one that is re-appearing in the view

    I have tried the refresh method on the dataview, various store load/sync methods. i have tried creating the store globally in app.js and local to my controller - none of which seem to have any effect and after days of trying to debug and trying anything i can find on this forum i am running out of ideas. Can anyone else out there spot anything?

    The above code is edited to keep it brief as possible but i think i only removed stuff that is irrelevent to this problem. i use a very recent build of Sencha Touch 2.1.1 btw

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448
    Answers
    3997

    Default

    With this simple test it's working for me with 2.1.1:

    Code:
    var i = 0;
    
    Ext.Viewport.add([
        {
            xtype   : 'dataview',
            itemTpl : '{foo}',
            store   : {
                fields : ['foo']
            }
        },
        {
            xtype : 'toolbar',
            docked : 'top',
            items  : [
                {
                    text    : 'Remove and Add Item',
                    handler : function() {
                        var list  = Ext.Viewport.child('dataview'),
                            store = list.getStore();
    
                        store.removeAll();
                        store.add({
                            foo : 'bar ' + i
                        });
    
                        i++;
                    }
                }
            ]
        }
    ]);
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Location
    Denmark
    Posts
    71
    Answers
    1

    Default my dataview does not update correctly on .load() after removeAll()

    Hi
    I am not sure if this relates to the issue above, but I'm in Sencha Touch 2.2.0 and trying to update a dataview-list using the removeAll/load routine.
    My isssue is that old data is not removed from the list and the new data is just added to the bottom of the list. If I try to load fewer dataitems than the first load, then only the new dataitems is counted and that number of dataitems is shown. However the dataitems shown is from the original load.

    with 2.0.0 I didn't need the removeAll() or remove() or anything. I have tried all the suggested ways of removing everything from the store.

    What I've noticed is that the update method for my dataview-item fields is not called.

    Any suggestions is highly appreciated.

    EDIT: adding a 'dataMap' config to my list item view solved my problem.
    Last edited by hjeDK; 2 Jul 2013 at 11:29 PM. Reason: new knowlegde

  4. #4
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    15

    Default Potential Solution

    I ran into the same issue. I had to manually call dataview.refresh() after clearing the store.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •