PDA

View Full Version : [OPEN] [#365] store GetChangedData does not account for filtered row



jchau
Oct 23, 2013, 10:44 PM
I have a grid with filter plugin. If user makes some changes to the grid, then apply filter, store.getChangedData will not return records that are modified but currently filtered out. Is there an option to account for all data in the store?

I would argue that getChangedData should always look at all records instead of filtered ones. I can't imagine a scenario where we only care about filtered records.

Baidaly
Oct 23, 2013, 11:08 PM
Hello!

This functionality based on the Sencha's logic but we'll discuss this.

For now, please, try to use the following:


App.GridPanel1.getStore().snapshot.filterBy(App.Gr idPanel1.getStore().filterUpdated).items;

Daniil
Oct 24, 2013, 5:07 AM
Here is also a possible solution.
http://forums.ext.net/showthread.php?23827&p=104278&viewfull=1#post104278

jchau
Oct 24, 2013, 3:50 PM
We have over 25 pages with grids. It will be nice if the functionality is built-in so we don't have to go back and modify 25 pages, plus do an extra round of testing. IMO, this is a bug since store.getChangedData should return all modified records regardless if a filter has been applied. This seems like an easy fix in your code since getChangedData is implemented by Ext.NET and not Sencha.

Baidaly
Oct 24, 2013, 4:50 PM
This method based on Sencha's functionality which we wouldn't like to change due to possible bugs.

You can try to use the following overriding based on Daniil's post:


<script>
Ext.data.AbstractStore.override({
getChangedData: function (options) {
options = options || {};

var data;
if (this.isFiltered()) {
data = this.data;
this.data = this.snapshot;
}

var json = {},
me = this,
obj,
newRecords = this.getNewRecords(),
updatedRecords = this.getUpdatedRecords(),
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;
}
}

if (this.isFiltered()) {
this.data = data;
}

return options.encode ? Ext.util.Format.htmlEncode(json) : json;
}
});
</script>

Daniil
Oct 25, 2013, 5:30 AM
Well, your statements make sense. But indeed, it is by design on the ExtJS level. A Store's sync method behaves in the same way. I think we are not going to make such a global change in the behavior of the Data package.

I found a related thread on the Sencha forum and updated it with a new post.
http://www.sencha.com/forum/showthread.php?189190

Hopefully, they will answer something.

Daniil
Oct 29, 2013, 2:00 PM
Created an Issue:
https://github.com/extnet/Ext.NET/issues/365

cwolcott
Nov 08, 2013, 4:12 AM
Never noticed this before.

For my GridPanel I build a StatusBar text message based on what has been touched no matter the filter. So I will need the getNewRecords, getUpdatedRecords and getRemovedRecords to return all changes not the the filtered set.

I directly call Store sync which will also need to process all the data. I will take a look at this tomorrow.