View Full Version : can't remove record in grid.
Alexei Ptitchkin
16 Jul 2012, 11:24 AM
I have really weird misbehavior. In code snippet I take selected row and pass it to store's remove method.
in fire bug I see that record is what I've selected, inspect store and confirm that record exists there. But when I step into dealerStore.remove I see that index = me.data.indexOf(record); return -1. The store "think" that record does not exists and do not remove it.
var dealerGrid = me.getDealerSetupGrid();
var dealerStore = me.getDealersDealerStore();
var record = dealerGrid.getSelectionModel().getSelection()[0];
dealerStore.remove(record);
Can you give me an idea what going on and how I can resolve issue.
Thank you in advance.
scottmartin
16 Jul 2012, 2:58 PM
what is the value of record ..
console.log(record);
Scott.
Alexei Ptitchkin
16 Jul 2012, 3:18 PM
If I understand your question you need to see how record object looks like in firebug inspector?
I feel that this isn't ExtJs problem, but rather data reference problem.
Unfortunately I'm away from my office computer and will be able to answer tomorrow morning.
Thank you for your help.
Alexei Ptitchkin
17 Jul 2012, 4:22 AM
Here we go.
37224
Alexei Ptitchkin
17 Jul 2012, 10:54 AM
on top described problem Store don't detect new records and call 'update' url instead of 'create'.
var win = button.up('window');
var form = win.down('form');
if (!(form.form.isValid())){
return;
}
var record = form.getRecord();
var values = form.getValues();
record = Ext.create('Fast.model.dealers.DealerModel');
record.set(values);
record.setId(-1);
dealerStore = this.getDealersDealerStore();
dealerStore.add(record);
dealerStore.sync();
Please help.
scottmartin
17 Jul 2012, 12:02 PM
When you set the id, you are making it an existing record .. instead of new
record.phantom should be true, and you are making it false.
The servers should return the ID on a new record and should not be set by the client.
Scott.
Alexei Ptitchkin
17 Jul 2012, 12:52 PM
Thank you Scott. It works.
But still it's very weird because in ExtJS 4.0.0 this code works even I set Id.
I'm doing refactoring and switch to ExtJs 4.1.0.
Also could you please help me figure out why I can't delete record (initial post.)
scottmartin
17 Jul 2012, 1:03 PM
Can you send the record itself as presented in the console instead of a pic. I was unable to see all that was needed to determine if the record was valid.
The other aspect is, does the server side get the data in a format it expects and know how to process it?
Scott.
Alexei Ptitchkin
17 Jul 2012, 1:36 PM
Record in console:
Object { internalId=
228, raw={...}, data={...}, more...}
in inspector :
$className
"Fast.model.dealers.DealerModel"
$hasInheritableStatics
Object { setProxy=
true, getProxy=
true, setFields=
true, more...}
$inheritableStatics
[
"setProxy",
"getProxy",
"setFields", 2 more...]
_singleProp
Object {}
alternateClassName
"Ext.data.Record"
associations
Object { items=[0], map={...}, keys=[0], more...}
clientIdProperty
null
config
Object {}
configMap
Object {}
data
Object { id=
228, dealerCode=
"C948", dealerName=
"MAXWELL'S FOTO SOURCE", more...}
dealerCode
"C948"
dealerName
"MAXWELL'S FOTO SOURCE"
hasDefaultAllocation
"N"
hasForecast
"Y"
hasQuota
"Y"
hasSellHand
"N"
id
228
defaultProxyType
"ajax"
dirty
false
editing
false
eventOptionsRe
RegExp /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate|element|vertical|horizontal|freezeEvent)$/
evented
false
events
Object {}
fields
Object { items=[7], map={...}, keys=[7], more...}
hasListeners
Object { itemdblclick=
1, click=
1}
id
"Fast.model.dealers.DealerModel-228"
idProperty
"id"
idgen
Object { isGenerator=
true, type=
"default", generate=function(), more...}
index
25
initConfigList
[]
initConfigMap
Object {}
internalId
228
isInstance
true
isModel
true
isObservable
true
mixins
Object { observable={...}}
modelName
"Fast.model.dealers.DealerModel"
modified
Object {}
persistenceProperty
"data"
phantom
false
proxy
Object { type=
"ajax", hasListeners={...}, events={...}, more...}
raw
Object { dealerCode=
"C948", dealerName=
"MAXWELL'S FOTO SOURCE", hasDefaultAllocation=
"N", more...}
requires
[Object { all={...}, types={...}, superclass={...}, more...}, constructor(), constructor(), 4 more...]
store
Object { data={...}, groupers={...}, extend=
"Ext.data.Store", more...}
stores
[Object { data={...}, groupers={...}, extend=
"Ext.data.Store", more...}]
superclass
Object { superclass={...}, config={...}, initConfigList=[0], more...}
validations
[]
HasListeners
function()
self
constructor()
addEvents
function()
addListener
function()
addManagedListener
function()
afterCommit
function()
afterEdit
function()
afterMethod
function()
afterReject
function()
beforeMethod
function()
beginEdit
function()
callOverridden
function()
callParent
function()
callStore
function()
cancelEdit
function()
clearListeners
function()
clearManagedListeners
function()
commit
function()
compareConvertFields
function()
configClass
function()
constructor
function()
continueFireEvent
function()
copy
function()
copyFrom
function()
createRelayer
function()
destroy
function()
enableBubble
function()
endEdit
function()
fireEvent
function()
get
function()
getAssociatedData
function()
getBubbleParent
function()
getChanges
function()
getConfig
function()
getData
function()
getId
function()
getInitialConfig
function()
getModifiedFieldNames
function()
getObservableId
function()
getProxy
function()
hasConfig
function()
hasListener
function()
initConfig
function()
isEqual
function()
isModified
function()
isValid
function()
itemNameFn
function()
join
function()
mon
function()
mun
function()
on
function()
onClassMixedIn
function()
onConfigUpdate
function()
prepareAssociatedData
function()
reject
function()
relayEvents
function()
removeListener
function()
removeManagedListener
function()
removeManagedListenerItem
function()
removeMethodListener
function()
resumeEvents
function()
save
function()
set
function()
setConfig
function()
setDirty
function()
setId
function()
setProxy
function()
statics
function()
suspendEvents
function()
toggleEventLogging
function()
un
function()
unjoin
function()
validate
function()
__proto__
Object { superclass={...}, config={...}, initConfigList=[0], more...}
If I understand 2nd question correctly. Server do not receive anything because no record selected to be removed, so Store do not send anything to server.
scottmartin
17 Jul 2012, 3:26 PM
You should be able to use:
var record = dealerGrid.getSelectionModel().getSelection();
Scott.
Alexei Ptitchkin
17 Jul 2012, 3:29 PM
I've tried that we the same result.
Inside method Store:remove() argument wrapped in array, so it's safe to pass either One record or array of records.
scottmartin
17 Jul 2012, 3:44 PM
There must be another issue, or this is something so simple it is overlooked.
If you issue the store.remove(record) .. then is nothing in the header sent to server?
Scott.
Alexei Ptitchkin
17 Jul 2012, 3:55 PM
Inside store.remove(record) uses standard javascript method indexOf(record) and this "indexof" return -1.
Alexei Ptitchkin
18 Jul 2012, 9:47 AM
So I had to write my own delete record in store
var dealerGrid = me.getDealerSetupGrid();
var dealerStore = me.getDealersDealerStore();
var record = dealerGrid.getSelectionModel().getSelection()[0];
var idx = -1;
var dataArray = dealerStore.data.items;
var i;
//TODO - <AP> !!! can't find record in store so does NOT delete it.
//dealerStore.remove(record);
for(i=0; i< dataArray.length;i++){
if (dataArray[i].data.id == record.data.id){
idx = i
break;
}
}
if(idx != -1){
dealerStore.removeAt(idx);
dealerStore.sync();
}
because this code correctly remove record from store and and sync with server I think that Store:remove() method can't find complex records and this is a bug.
As a solution I may suggest to introduce Model.equal(Model record) method which will be used in Store.remove.
PS. in previous version of our application (there is ExtJs 4.0.0) Store.remove(record); works fine.
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.