PDA

View Full Version : How to assign record using Ext.data.Record.create?



yagi
2 Aug 2010, 8:50 PM
Hi All..

I have a grid and it is using Ext.data.Record.create().
According to docs about Ext.data.Record.create(), it is written that to assign value to the record we have to create the record instance.
Ex :


var myNewRecord = new TopicRecord(
{
title: 'Do my job please',
author: 'noobie',
totalPosts: 1,
lastPost: new Date(),
lastPoster: 'Animal',
excerpt: 'No way dude!'
},
id // optionally specify the id of the record otherwise one is auto-assigned
);

But, How to set the value more than 1 row based on the example above?

Thanks in Advance..

Condor
2 Aug 2010, 10:50 PM
How to set the value more than 1 row based on the example above?

I don't understand the question...

yagi
2 Aug 2010, 11:07 PM
Ups.., I'm sorry..

I mean.., how to set the record more than 1 row. Because, based on the example in the docs.., it only shows static data, it is 1 row. How about I want to set more than 1 row? I don't know How to achieve that.

Could you help me please?

Thanks a lot..

Condor
2 Aug 2010, 11:38 PM
I still don't understand: "how to set the record more than 1 row" isn't valid english.

You want to add more than one row? Simply create multiple records and add them to the store.

yagi
3 Aug 2010, 12:20 AM
I'm sorry Condor for my bad english.
Yes.., that's what I mean..

Hmmm.., Do you mean like this?


var myNewRecord = new TopicRecord(
{
title: 'Do my job please',
author: 'noobie',
totalPosts: 1,
lastPost: new Date(),
lastPoster: 'Animal',
excerpt: 'No way dude!'
},
{
title: 'Do my job please',
author: 'noobie',
totalPosts: 1,
lastPost: new Date(),
lastPoster: 'Animal',
excerpt: 'No way dude!'
},
id // optionally specify the id of the record otherwise one is auto-assigned
);
myStore.add(myNewRecord);

Condor
3 Aug 2010, 12:23 AM
That should be:

var myNewRecords = [
new TopicRecord({
title: 'Do my job please',
author: 'noobie',
totalPosts: 1,
lastPost: new Date(),
lastPoster: 'Animal',
excerpt: 'No way dude!'
}, id1),
new TopicRecord({
title: 'Do my job please',
author: 'noobie',
totalPosts: 1,
lastPost: new Date(),
lastPoster: 'Animal',
excerpt: 'No way dude!'
}, id2)
];
myStore.add(myNewRecords);

yagi
3 Aug 2010, 1:22 AM
Thanks Condor, It works..

Anyway, can we add row dynamically?

so, it uses looping for adding multiple records..

Thanks a lot..

Condor
3 Aug 2010, 1:40 AM
Simple javascript:

var myNewRecords = [];
for (var i = 0; i < 100; i++) {
myNewRecords.push(new TopicRecord({
title: 'Item no. ' + i,
author: 'noobie',
totalPosts: 1,
lastPost: new Date(),
lastPoster: 'Animal',
excerpt: 'No way dude!'
}, 'record-id-' + i));
}
myStore.add(myNewRecords);
(maybe you should read up on general javascript coding)