-
19 Apr 2012 6:25 AM #1Ext JS Premium Member
- Join Date
- Nov 2010
- Location
- Dillenburg, Hessen, Germany
- Posts
- 35
- Vote Rating
- 0
[EXT 4.1 RC3] loading phantom records from the backend into a grid
[EXT 4.1 RC3] loading phantom records from the backend into a grid
i have a strange problem and can't find anything about...
i have a grid (models+store+...) that is loaded from my backend via REST.
the backend sends a list of objects (some with id - these records exist in the database, and some without id - these records are phantom records).
with ExtJS 4.0.7 this worked perfect, the records with id became the right id and the records without id where added as phantom records to the grid.
since the update to 4.1 RC2/RC3 the records without id get the id 0 and are not phantoms
this is really a problem, cause the user should save (create) the phantom records to the database by click on them. but Ext thinks they already exist in the database and tries to update them (REST) and this fails in the database.
So what changed with the model/id/phantom stuff?
-
19 Apr 2012 7:18 AM #2
When you say the backend sends a list of items .. you are referring to the data returned by the server?(some with id - these records exist in the database, and some without id - these records are phantom records).
I will need more details about this as the server has full control at this point of what is send back.
Regards,
Scott.
-
19 Apr 2012 7:24 AM #3Ext JS Premium Member
- Join Date
- Nov 2010
- Location
- Dillenburg, Hessen, Germany
- Posts
- 35
- Vote Rating
- 0
the backend is our own php server side. so the server sends json like
they all came to the store as real models and none of them is a phantom.Code:{ result: [{ id: 50, text: "entry from database" },{ id: null, text: "fake entry should be phantom" },{ text: "also tried fake entry without id" },{...},...] }
with Ext 4.0.7 the records with id: null where phantom records.
-
19 Apr 2012 7:42 AM #4
in reviewing the code I see 4.1 did add the following:
You can try a quick override test for your model see if that helps:Code:setId: function(id) { this.set(this.idProperty, id); this.phantom = !(id || id === 0); // << added in 4.1 },
Regards,Code:Ext.override(Ext.data.Model, { setId: function(id) { this.set(this.idProperty, id); } });
Scott.
-
19 Apr 2012 8:03 AM #5Ext JS Premium Member
- Join Date
- Nov 2010
- Location
- Dillenburg, Hessen, Germany
- Posts
- 35
- Vote Rating
- 0
that was also the line i found but i'm very confused because to me it seems that this method is never called.
i did a console.log in the override that never came. the override itself works (checked by also overriding the constructor and did a log there and called the overridden.
the construct log came the other did neverCode:Ext.override(Ext.data.Model, { constructor: function() { console.log("CONSTRUCT MODEL"); this.callOverridden(arguments); }, setId: function(id) { console.log("MODEL SET ID", id); this.set(this.idProperty, id); } });
-
20 Apr 2012 4:12 AM #6Ext JS Premium Member
- Join Date
- Nov 2010
- Location
- Dillenburg, Hessen, Germany
- Posts
- 35
- Vote Rating
- 0
my workaround now is to set the phantom flag on the beginning of the first column renderer if there is no id.
that isn't really nice but it works, and as far as my debugging skills in the ext source go, it seems to be a problem there but i really don't get the construction of an model and when there is the data to be set...
a fix or hint for my problem that is not that ugly as my one would be nice...
-
23 Apr 2012 11:15 PM #7
did you try to set the model property useNull:true ?
Example:
Ext.define("CurrencyDs" ,{
extend: 'Ext.data.Model',
fields: [
{name:"name", type:"string"},
{name:"code", type:"string"},
{name:"active", type:"boolean"},
{name:"notes", type:"string"},
{name:"id", type:"int", useNull:true},
............
],
.....
});
-
24 Apr 2012 12:35 AM #8Ext JS Premium Member
- Join Date
- Nov 2010
- Location
- Dillenburg, Hessen, Germany
- Posts
- 35
- Vote Rating
- 0
yes i did, but didn't help.
after that model.get('id') returned null as is should but model.phantom is/was false anyway


Reply With Quote