PDA

View Full Version : Noobee question on Grid.



NTR
4 Oct 2007, 11:32 AM
Hi,
I'm struggling to understand EXTJS (I'm not that great in javascript still learing it).
I'm trying to implement data grid functionality and confused of how to add an ID to the record object using Ext.Record.create() method.
When I click on some link say 'Add record1', I want to add a record to the grid ex (Name:Record1, Number of Clicks:1). Whan I click on 'Add record2', I want to add another record to the grid ex (Name:Record2 Nubmer of Clicks:1).
Multiple clicks on the same link will have to increment the click count in corresponding record.

As explained in the api doc, I need to create a record and add to the store as following:


var TopicRecord = Ext.data.Record.create(
{name: 'title', mapping: 'topic_title'},
{name: 'author', mapping: 'username'},
{name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
{name: 'lastPost', mapping: 'post_time', type: 'date'},
{name: 'lastPoster', mapping: 'user2'},
{name: 'excerpt', mapping: 'post_text'}
);

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

My question is how to assign custome id to the record

My pseudo code:
var TopicRecord;
var dataStore;
Ext.onReady(function(){
TopicRecord = Ext.data.Record.create(
{name: 'linkName', mapping: 'linkName'},
{name: 'clicks', mapping: 'clicks'}
);
dataStore = new Ext.data.Store({});
var colModel = new Ext.grid.ColumnModel([
{header: "Link Name ", width: 150, dataIndex: 'linkName'},
{header: "Number of Clicks", width: 60, dataIndex: 'clicks'}
]);
mydataGrid = new Ext.grid.GridPanel({
title: 'My Click Grid',
ds:dataStore,
cm:colModel,
viewConfig: {
forceFit:true
},
width: 300,
height: 200,
collapsible: true,
animCollapse: false,
iconCls: 'icon-grid'
});
)};
in the link onclick method:
var linkClick = function(linkName,id){
if(dataStore.getById(id))
{
increment record.click
}
else
{
var myNewRecord = new TopicRecord({
linkName: 'My Link1',
click: 1
});
dataStore.add(myNewRecord);
}};

NTR
5 Oct 2007, 5:27 AM
I must be missing a simple concept... any help...