Vikas Hire
Vikas Hire

Reputation: 628

Remove record by id from store in extJs/ Sencha

I Want to Remove record by Id. Eg. store contains RoleId, RoleName fieds.

there are many records in store, I have RoleId to remove/delete record from store. belove code I already tried but not working.. can you give me some suggestions for this.

  roleId = Ext.getStore('userStore').first().data.roleId;
                    var roleStore = Ext.getStore('userStore').first().companies().first().roles();
                    roleStore.remove(roleStore.findRecord('roleId', roleId));

And also tried...

  roleId = Ext.getStore('userStore').first().data.roleId;
                    var roleStore = Ext.getStore('userStore').first().companies().first().roles();
                    roleStore.removeAt(roleStore.find('roleId', roleId));

Upvotes: 0

Views: 3620

Answers (1)

Harshit Shah
Harshit Shah

Reputation: 266

You can directly try this,

roleId = Ext.getStore('userStore').first().data.roleId;
var roleStoreItems = Ext.getStore('userStore').first().companies().first().roles().data.items;
roleStoreItems.forEach( function(item,index){
if(item.data.roleId==roleId){
roleStoreItems.remove(index);
}
});

Upvotes: 1

Related Questions