Reputation: 5654
I have a dgrid which only has one column of data (name) however i am attempting to preform an update on this column and it keeps inserting a new record. I understand it will treat the information entered as a new record since the idProperty in the dgrid is = name. How can i over come this issue and be able to update the selected column without preforming a new update.
I also understand dgrid does not implement the concept of a row index. Under is my code:
Dgrid
var nameStore = new dojo.store.Observable(new Memory({data: data, idProperty:"name"}));
var nameGrid = new CustomNameGrid ({
store: nameStore,
columns: {
chkBox:selector({}),
Name:{
label:"Names",
field:"name"
}
} ,
selectionMode:"none",
loadingMessage: "Loading data...",
noDataMessage: "No results found....",
allowSelectAll: true
}, "nameGrid");
Data
var data = [{name:"ABC"},
{ name:"DEFG"},
{ name:"HIJK LMNOP"}];
Update Function
Once the update button is clicked an update function is fired, the function works excepts it inserts a new row instead of updating the selected row. The main statement in the update function is
var userEnteredName = document.getElementById('nameEntered').value
aliasStore.put({name:userEnteredName});
Upvotes: 0
Views: 280
Reputation: 56
Add an id
field to your data and remove the idProperty
from your Memory store or set it to "id". When you want to update a row, use the id from the selected row and set name
to the new value.
nameStore.put({id:selectedRowId, name: userEnteredName});
Life is better when you generate primary keys rather than use business data because you run into problems when that business data needs to change.
Upvotes: 3
Reputation: 3528
Its worth (if you are using a Memory store to back your dgrid data) checking the put directives being used when you perform an update on an existing row, check the Dojo PutDirectives API for details.
Maybe you need to set overwrite
to true when doing the put()
?
Upvotes: 1