My First ExtJS DataGrid Pt 7: Custom Cell Renderers
So, it's been awhile. No, I haven't forgotten you, I've just been busy with a lot of things. One of which has been implementing a new ExtJS DataGrid in a project I'm working on. Sure, there's a lot more going on, but that's becoming a nice front end piece. As previously promised, I want to look at a renderer.
What Is A Renderer?
Hey, not everything you get back from your paging query will be formatted in the way you want it displayed. I'm going to show you a really simple example, dealing with a boolean value. Let's start off by writing a renderer function. Here's the deal, you have a query column with a boolean value (bIsActive), which is returned as either 1 or 0. You want the grid to display Yes or No. You could define the function directly in your ColumnModel declaration:,{
header:'Active',
dataIndex:'bIsActive',
renderer:function(value){
return (value == 1)?'Yes':'No';}
}
...
A renderer function will take at least one argument by default, that being the value of the cell being rendered. You do not explicitly call a renderer, the arguments passed to the renderer are dependent upon the function definition. For something as simple as a Yes/No boolean renderer the value is all that's necessary. So you would define a renderer function, and register it, like this:
return String.format("{0}",(value==1)?'Yes':'No');
}
// And a redefinition of of the renderer in the ColumnModel
...
,{
header:'Active',
dataIndex:'bIsActive',
renderer:renderBoolean
}
...
return String.format("{0} {1}", value, r.data['vcLastName']);
}
// Combine our 'name' columns into one
...
,{
header:'Name',
dataIndex:'vcFirstName',
renderer:renderName
}
...
You'll also want to note the the JavaScript bind variable syntax being used in the String.format() function, {[value]}. The numbers used here are like array position values, starting at zero, for all of the variables passed in the arguments that follow the string you are formatting (the first argument of the function).
So, that's a quick down and dirty on renderers. No download with this particular post, but the code samples above aren't overly difficult to integrate. You can, absolutely, do some much more complex renderer functions, but this should be a good start.


I know this is not a forum, but i'm working on a problem now with extjs, and being a noobiwe its hard to write the good code for working, and i'm wondering if your experince confrunt with some similar problem.
So i wanna do a master/details relationship between 2 grids in extjs. Thats consist in:
- i have 2 grids, first is a master and second is the slave grid.
- when i select a row in the first grid the second one, the slave grid will show me the results depending on the id_row selected in the first grid.
This is the problem, and i'm wondering if you had some experience with that and if you can post some example.
It wiil be greatfull.
Thx in advance!
hth
I am amit, I just want help from u tht is is possible to provide a link through which if we point to a particulat element in a grid then we can provide another window if user want.