PDA

View Full Version : Any way to Render a Grid Item based on another column value?



Syed Huda
13 Dec 2010, 3:53 PM
Hello,

I'm trying to follow this example where the array grid item uses renderer to make it red or green based on the item value:
http://dev.sencha.com/deploy/dev/examples/grid/array-grid.html

This is the function that makes the change:

function change(val) {
if (val > 0) {
return '<span style="color:green;">' + val + '</span>';
} else if (val < 0) {
return '<span style="color:red;">' + val + '</span>';
}
return val; }



And the rendere is used here in the column model:

{
header : 'Change',
width : 75,
sortable : true,
renderer : change,
dataIndex: 'change'}


Is there a way to pass another item for "val"? For example I have a column 'Change 2', and depending on the value of that column I want to use a renderer to make 'Change' column red.

Hope this makes sense.

arthurakay
14 Dec 2010, 6:06 PM
Look at the API docs for Column:
- http://dev.sencha.com/deploy/dev/docs/?class=Ext.grid.Column

Scroll down to the renderer property.


renderer: function renderer(val, metaData, record, rowIndex, colIndex, store) {
//your logic here
}

Use "record.get('someVal')" to access the other fields on your record.

iplanit
2 Oct 2012, 3:20 AM
It works for me.

I just changed the style of a cell depending on the value, just adding value instead of val (in Sencha Architect) with the style works. Thank you for the advice about the styling.

Regards


Look at the API docs for Column:
- http://dev.sencha.com/deploy/dev/docs/?class=Ext.grid.Column

Scroll down to the renderer property.


renderer: function renderer(val, metaData, record, rowIndex, colIndex, store) {
//your logic here
}

Use "record.get('someVal')" to access the other fields on your record.