PDA

View Full Version : need a single row of a column to be rendered into diffrent Datatype



kankit28
17 Dec 2009, 5:48 AM
Hi,

I am having a JSON store :
var testGridStore = new Ext.data.JsonStore({
url: '../../model/getData.php',
fields: [
{name: 'metricName',type: 'string'},
{name: 'datatypeName',type: 'string'},
{name: 'queueName', type: 'string'},
{name: 'current', type: 'int'},
{name: 'target', type: 'int'},
{name: 'weekend',type: 'date',dateFormat: 'Y-m-d'}
],
sortInfo:{field: 'metricName', direction: "ASC"}
});

The column Model for the GridPanel is as follows :

columns:[
{id:'metricName',header:'Metric Name',sortable:true,dataIndex:'metricName'},
{id:'datatypeName',header:'datatypeName',sortable:true,dataIndex:'datatypeName'},
{id:'queueName',header:'Queue Name',sortable:true,dataIndex:'queueName'},
{id:'current',header:'current',dataIndex:'current',renderer: dataTypeRender},
{id:'target',header:'target',dataIndex:'target',renderer: dataTypeRender},
{id:'weekend',header:'weekend',sortable:true,dataIndex:'weekend',renderer: Ext.util.Format.dateRenderer('Y-m-d')}
],

I want to show the column "current" & "target" values according to the "datatype" column details
so in the renderer I am using the function "dataTypeRender"


Function is as follows:
function dataTypeRender(val){
console.log(testGridStore.getAt(1).get('datatypeName'));
var datatypeName = testGridStore.getAt(1).data.datatypeName;
switch(datatypeName){
case 'PERCENTAGE':
console.log('I came in percent');
return val+"%";
break;
case 'DOLLAR':
console.log('I came in Time');
return "$ " +val;
break;
default:
val;
}

But testGridStore.getAt(1).get('datatypeName') is not working out .
need suggestions

realjax
17 Dec 2009, 5:59 AM
Are you sure that arrays being zero-based is not your problem ?

You are requesting the second record in your example, does that one exist?

kankit28
17 Dec 2009, 7:24 AM
Yeah the record Exist The problem is . I am getting the result of the following :

testGridStore.getAt(1).get('datatypeName')

as only one record not for all the rows its just giving me the result for the one cell and showing in all requests.

realjax
17 Dec 2009, 9:56 AM
testGridStore.getAt(1).get('datatypeName')

as only one record not for all the rows its just giving me the result for the one cell and showing in all requests.

Yes, because that is exactly what you ask for. you're saying: Give me the value of datatypeName of the record at row 1. Everytime. For every row you call the renderer on.

The renderer function also receives a record in it's arguments and that is what you need to use. Checks the docs for grid.column. Have a look at the renderer property

kankit28
17 Dec 2009, 8:34 PM
is there anyway we can get record for every row ??

kankit28
17 Dec 2009, 10:41 PM
I was able to crack that out.
In renderer function dataTypeRender(val,rowIndex,record)

The record.data.<<columnName>> has given me the desired result and i can modify my single column in different datatypes while rendering .

realjax
17 Dec 2009, 11:49 PM
Yeah, just like I said.