Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:37:36+00:00 2026-06-10T03:37:36+00:00

I have a grid panel with one grid model. How can I set primary

  • 0

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?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:37:38+00:00Added an answer on June 10, 2026 at 3:37 am

    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:

    var myStore = Ext.create("Ext.data.Store", {
        listeners: {
            add: function(store, records){
                var checkRecords = store.getRange();//get the records to check against
                //clean out the records from the set that were just added
                for(var i = 0; i < records.length; i++)
                    Ext.Array.remove(checkRecords, records[i]);
    
                for(var i = 0; i < checkRecords.length; i++)
                {
                    for( var j = 0; j < records.length; j++)
                    {
                        if(checkRecords[i].get("primary_key") == records[j].get("primary_key"))
                            throw "Duplicate primary key: " + records[j].get("primary_key");
                    }
                }
            }
        }
    });
    

    That code will throw an exception but not stop the record for being added.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view designed like that: Ext.define('MY.view.NotificationMails', { extend: 'Ext.grid.Panel', alias: 'widget.NotificationMailsPanel', id:
So I have a ExtJs 4 Grid Panel that has two columns. Column ONE
I have grid something like this: Ext.define('Exp.view.dashboard.Tv', { extend: 'Ext.grid.Panel', initComponent: function() { this.columns
I have added checkbox selection model to grid panel. It works fine in IE8
I have a set of records in a panel grid where I want to
I have a tab panel that gets populated with a grid when a button
I hope I can explain this properly. I have a grid that is part
I have 4-5 grid panels, one form panel and want to put it into
I have defined xtype that is simple grid with 2 columns and selModel: Ext.selection.CheckboxModel.
I have a grid panel in ExtJS 4 with the following features: extend :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.