Nick Div
Nick Div

Reputation: 5628

Is it possible to set Custom ID to sencha touch records

When I am loading store on a sencha touch Grid the records have a auto-generated ID for e.g. "ext-records-5", "ext-records-6" etc etc,

The columns that I am getting from the server are as follows: "eId", "name", "number"

In my data.Model I have set the idProperty: 'eId' assuming that it will set the eId coming from the server as the ID of the record but all this seems to do is set the internalId as 'eId'

This is not what I am looking for, has anyone come across a situation like this or can anyone figure out a way to acheive what I am looking for.

Any help would be appreciated.

Thanks in advance.

Upvotes: 0

Views: 305

Answers (1)

Apoorv Nag
Apoorv Nag

Reputation: 1279

By default idProperty:'id' is considered, sencha generates automatic ids by itself depending on the identifier strategy you choose which can be either simple, sequential or uuid. But as soon as you say idProperty: 'eId', this means sencha will not generate any ids for you. Either we can use eId or we can directly accept the value by using field name as id as shown below. So in the case shown below, I have used id instead of eId

Ext.define('StoreDemo.model.LSModel', {
    extend: 'Ext.data.Model',
    
    config: {
        fields: [
            { name: 'id', type: 'auto' }, // use id instead of eId
            { name: 'name', type: 'int' },
            { name: 'number', type: 'int' }

        ],
        idProperty:'id' , //By default idProperty is 'id'
        // idProperty:'uname' ,
        proxy:{
        	type:'localstorage' // or 'sessionstorage'
        },

        /*identifier:{
            type:'simple'  //The id is given by Ext e.g. ext-record-1,ext-record-2
        	// type:'uuid'  //This generates a unique id everytime we save a model
        }*/	
    }
});

When you are getting the data through server like use a separate model with field name as eId and assign the model into the an another model of LSModel mentioned above.

Upvotes: 0

Related Questions