[CLOSED] Get all changed store data when store is filtered

  1. #1

    [CLOSED] Get all changed store data when store is filtered

    Hello,

    I use below code as extra parameter for batch saving of a grid store data.
    App.MyStore.getChangedData({skipIdForNewRecords : false})
    UI allows user filter store with:
    App.MyStore.filterBy(filterFn);
    Details: Grid panel store is filtered by TreePanel node select handler.

    Normally, if the store is filtered before save, changed records not matching filterFn are not in getChangedData collection. (I guess that is expected situation.)

    Well, what I want to do is, saving all changed data while not clearing the store filter. How can I get all changed data on a filtered store? Can you suggest a replacement or workaround instead of getChangedData or suggest another way to filter grid view without filtering grid store?

    Thanks.
    Last edited by Daniil; Mar 12, 2013 at 5:44 AM. Reason: [CLOSED]
  2. #2
    Hello!

    What kind of filtration do you use: remote or local?
  3. #3
    Quote Originally Posted by Baidaly View Post
    Hello!

    What kind of filtration do you use: remote or local?
    Hello, it should be local filtering but i don't know the difference well. Store binds remote data from DB but filtering is done with store.filterBy at client side.

    Thanks.
  4. #4
    Hi,

    Remote filtering means that all data is filtered on a server. So, if some data are not passed filtering conditions, that data are not sent to a client. So, the getChangedData method would not be able to retrieve that data on a client.

    In a case with local filtering, the getChangedData method has the access to all the data. To filter records please use the filterRecord option.

    Example
    var filterFn = function (rec) {
        return rec.getId() === 1;
    }
    
    App.Store1.filterBy(filterFn);
    
    App.Store1.getChangedData({
        filterRecord: filterFn
    })
  5. #5
    Quote Originally Posted by Daniil View Post
    Hi,

    Remote filtering means that all data is filtered on a server. So, if some data are not passed filtering conditions, that data are not sent to a client. So, the getChangedData method would not be able to retrieve that data on a client.

    In a case with local filtering, the getChangedData method has the access to all the data. To filter records please use the filterRecord option.

    Example
    var filterFn = function (rec) {
        return rec.getId() === 1;
    }
    
    App.Store1.filterBy(filterFn);
    
    App.Store1.getChangedData({
        filterRecord: filterFn
    })
    Hello Daniil,

    Thanks for your response. Yes it is local filtering for sure. I think I could not ask the question well or did not understand the answer. I don't want to filter records in getChangedData. Please see question below from your code.

    Let say the store has been filtered by:
    var filterFn = function (rec) {
        return rec.getId() === 1;
    }
    
    App.Store1.filterBy(filterFn);
    Using getChangedData() function, I want to get all changes not only the record with id === 1 even if the store is filtered. Did I get your answer wrong?
    You wrote "In a case with local filtering, the getChangedData method has the access to all the data. " But in my case (the same code above), getChangedData gets changed data only in filtered records. Ext.js documentation here also says "When store is filtered, most of the methods for accessing store data will be working only within the set of filtered records. Two notable exceptions are queryBy and getById." I am looking for an alternative way of filtering grid view without filtering store. Is there something wrong with my assumptions on getChangedData function? Is it possible to get all changes even if the store is filtered with filterBy function?

    Thanks.
  6. #6
    Sorry, I misunderstood your question.

    We will consider to add an option to retrieve all records including excluded by filters.

    For now I can suggest this method.

    getAllChangedData
    <script>
        Ext.data.AbstractStore.override({
            getAllChangedData : function (options) {
                options = options || {};
            
                var json = {},            
                    me = this,
                    obj,
                    newRecords = this.queryBy(this.filterNew).items,
                    updatedRecords = this.queryBy(this.filterUpdated).items,
                    removedRecords = this.getRemovedRecords(),
                    idProp = me.proxy && me.proxy.reader ? me.proxy.reader.getIdProperty() : "id",
                
                    handleRecords = function (array) {
                        var i,
                            len,
                            obj,
                            list,
                            buffer = [];
                        
                        for (i = 0, len = array.length; i < len; i++) {
                            obj = {};
                            record = array[i];
                            list = Ext.apply(obj, record.data);
    
                            if (list.hasOwnProperty(idProp)) {
                                if (record.phantom) {
                                    if (record.clientIdProperty) {
                                        list[record.clientIdProperty] = record.internalId; 
                                    }
                                } else {
                                    list[idProp] = record.getId(); 
                                }
                            }
    
                            list = this.prepareRecord(list, record, options, record.phantom);
                        
                            if (record.phantom && (options.skipIdForPhantomRecords !== false) && list.hasOwnProperty(idProp)) {
                                delete list[idProp];
                                delete list[record.clientIdProperty];
                            }
    
                            if (!Ext.isEmptyObj(list)) {
                                buffer.push(list);
                            }
                        }
                    
                        return buffer;
                    };
    
                if (removedRecords.length > 0) {            
                    obj = handleRecords.call(this, removedRecords);
    
                    if (obj.length > 0) {
                        json.Deleted = obj;
                    }            
                }
    
                if (updatedRecords.length > 0) {            
                    obj = handleRecords.call(this, updatedRecords);
                
                    if (obj.length > 0) {
                        json.Updated = obj;
                    }            
                }
            
                if (newRecords.length > 0) {            
                    obj = handleRecords.call(this, newRecords);
                
                    if (obj.length > 0) {
                        json.Created = obj;
                    }            
                }
    
                return options.encode ? Ext.util.Format.htmlEncode(json) : json;
            }    
        });
    </script>
  7. #7
    Quote Originally Posted by Daniil View Post
    We will consider to add an option to retrieve all records including excluded by filters.
    We will leave it for now, but will keep in mind.

    Here is, probably, the simplest way.

    var store = App.Store1,
        data = store.data,
        changedData
        
    store.data = store.snapshot; // does the trick
    changedData = store.getChangedData();
    store.data = data; // to revert the changes back

Similar Threads

  1. How to get the filtered data of GridPanel?
    By tesonguo in forum 1.x Help
    Replies: 5
    Last Post: Mar 08, 2012, 11:13 AM
  2. [CLOSED] Access Grid Data Store and manually store to database
    By macap in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 05, 2011, 8:52 AM
  3. [CLOSED] Get Store's Filtered Records
    By Juls in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 04, 2011, 7:42 AM
  4. Replies: 0
    Last Post: Dec 30, 2010, 1:13 AM

Posting Permissions