1. #1
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    384
    Vote Rating
    11
    murrah will become famous soon enough

      1  

    Default Tip: Remove records from store without triggering a proxy Destroy operation

    Tip: Remove records from store without triggering a proxy Destroy operation


    Hi,

    I had a situation where I needed to remove records from a store that got it's data via a REST proxy, but I didn't want to actually delete the records from the server, I just wanted them out of the store driving my grid.

    The way I was signaling which records to remove from the grid / store was by dragging them onto a particular tree node and catching the drop in beforeDrop, removing the dropped records from the grid then cancelling the drop.

    I was using store suspendAutoSync() which didn't sync the remove to the server (good) but found that when I did a subsequent drop, the previously dropped and removed records were being deleted from the server via a mysterious destroy operation! (bad).

    I discovered that the reason was that the removed records were being saved in the store's removed[] collection in the remove() method. What this meant was that any subsequent proxy operation had a "pending" destroy operation waiting for an opportunity to run.

    I also noticed that if I passed a second parameter to the remove() method (private, so it is not in the docs), that would prevent the record from being added to the removed[] collection and hence there would be no pending destroy.

    This is my code:
    PHP Code:
    data.records = [array of records to remove from the store]

    var 
    subjStore this.getVSubjectGrid().store;

    subjStore.suspendAutoSync();

    Ext.Array.each(data.records, function (recindex) {
        
    subjStore.remove(rectrue); //<--- passed true here to solve the problem
    });

    subjStore.resumeAutoSync(); 
    The second parameter to the remove() method is 'isMove' and the relevant part of the remove() method is:
    PHP Code:
    // don't push phantom records onto removed
    if (!isMove && isNotPhantom) {

        
    // Store the index the record was removed from so that rejectChanges can re-insert at the correct place.
        // The record's index property won't do, as that is the index in the overall dataset when Store is buffered.
        
    record.removedFrom index;
        
    me.removed.push(record);

    By setting isMove to true, the record is not added to me.removed[].

    I hope someone else might find this useful.

    Cheers,
    Murray
    Last edited by murrah; 8 Oct 2013 at 12:25 PM. Reason: Fix spelling

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,791
    Vote Rating
    833
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Thanks for posting the tip for the community!
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    384
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default


    No worries - great to put something back!

    And.... I realised that the remove() can take an array so this is a slight simplification of the code above:
    PHP Code:
    var subjStore this.getVSubjectGrid().store;                
    subjStore.suspendAutoSync();
                
                
    // Set true so that the record is NOT added to the store.removed collection 
                // so it doesnt fire a later destroy operation on the record        
    subjStore.remove(data.records,true);
        
    subjStore.resumeAutoSync(); 
    ie no need for my loop.

    Cheers,
    Murray

  4. #4
    Sencha User
    Join Date
    Apr 2010
    Posts
    75
    Vote Rating
    4
    HriBB is on a distinguished road

      0  

    Default


    WOW thanks for this one!

    I have two stores: Ext.data.Store and Ext.data.TreeStore which can both have the same record, but different instance. With store.remove(records, true) it works perfectly.

  5. #5
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    384
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default


    Quote Originally Posted by HriBB View Post
    WOW thanks for this one!
    Glad to help!

  6. #6
    Sencha Premium Member
    Join Date
    Aug 2013
    Posts
    12
    Vote Rating
    0
    shopeel is on a distinguished road

      0  

    Default


    Unfortunately it looks like your trick won't work in Sencha Touch (there is no secret second argument to "remove" as there is in Ext JS). Here's how I achieved the goal. This works in Sencha Touch and it might work in Ext JS as well.

    Code:
    var store = Ext.getStore("ExampleStore"),
        record = store.getbyId(123);
    record.phantom = true;
    store.remove(record);

  7. #7
    Sencha Premium Member sonata82's Avatar
    Join Date
    Aug 2011
    Posts
    19
    Vote Rating
    8
    sonata82 will become famous soon enough

      0  

    Default


    Thanks to this hint I was able to find a solution for my problem: removing a childnode from a tree, without the Store trying to remove the object on the server. Unfortanelty the remove function of NodeInterface does not have a parameter isMove, but removeChild has:

    Code:
    node = this.getStore().getNodeById(123);
    if (node.parentNode) {
        node.parentNode.removeChild(node, false, false, true); // <-- last parameter isMove
    }

  8. #8
    Sencha User
    Join Date
    May 2012
    Location
    Sweden
    Posts
    11
    Vote Rating
    2
    lp1051 is on a distinguished road

      0  

    Default Why private?

    Why private?


    I just needed the isMove trick today, and I need to ask, why is such a handy parameter private and not documented? Is Sencha planning new move() method and don't want us to learn soon deprecated stuff? Or can I use it without worries about the future?

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi