I have a grid panel with one grid model. How can I set primary key to that grid store so that I can prevent duplicate values. My model is:
Ext.define('product',{
extend : 'Ext.data.Model',
fields: [{name: 'name',type: 'string'},
{name: 'column1', type: 'int'},
{name: 'column2', type: 'int'}]
associations: [{type: 'belongsTo',model: 'product',primaryKey: 'column1'}]
});
How can I use this primary key to prevent entry of same record twice?!
You can’t ‘set’ a primary key on a model with Extjs. The concept itself does not exist in the library. The ID of the record needs to be unique, but there is really nothing that enforces it to be so. My question for you is, what do you even want done when a duplicate record is added? Do you want the values of the record to overwrite based on the key? Do you want an exception?
The best suggestion I can have for you is to use the ‘add’ event on the store and fill it with code something like this:
That code will throw an exception but not stop the record for being added.