PDA

View Full Version : help with renderer setup



piston
21 Feb 2011, 10:06 AM
I'm not much of a JS guy, so bear with me. I'm trying to get my renderer to work on this grid, and I'm not exactly sure what is wrong with this code:

Ext.onReady(function () {

var imgRenderer = function (data) {
if (data === 1) {
return "<img src=\'http://mysite.com/check.gif\'>";
} else if (data === 0) {
return "<img src=\'http://mysite.com/question.gif\'>";
}
};
...

// create the grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
expander,
{
header: "Name",
width: 120,
dataIndex: 'full_name',
sortable: true,
renderer: imgRenderer
...

piston
21 Feb 2011, 10:28 AM
I should have shown this too, I declared "data" in my store and reader:

var store = new Ext.data.Store({
// load using HTTP
url: 'http://www.mysite.com/beta/contact_echo.php',

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'contact',
id: 'record_id',
totalRecords: '@total'
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
'full_name', 'email', 'fax', 'type', 'active', 'method'])
});

Condor
21 Feb 2011, 10:59 AM
You didn't define a type for the full_name field, so it will contain a sting and not a number.

piston
21 Feb 2011, 11:02 AM
yeah, that's ok. The only column I want to use the renderer on is the "active" column.

piston
21 Feb 2011, 11:48 AM
you were right - I added this and it works - THANKS

{name: 'full_name'},
{name: 'email'},
{name: 'fax'},
{name: 'type'},
{name: 'active', type: 'float'},
{name: 'method'}
])