PDA

View Full Version : Grid record formater?



okwei
18 Mar 2009, 11:49 AM
I know the record for grid can have a converter, but this actually put the converted value into the store. This created a problem for me to sort this field.

Is there any kind of formater I can use to format the display without changing the underlying records themselves?

Thanks,

Joe
18 Mar 2009, 12:15 PM
Try using a renderer function .. defined in the columns config of the gridpanel. This will allow you to change the display .. but it won't effect sorting.

Let me know if you need an example of this in action.

Joe
18 Mar 2009, 12:23 PM
Before I posted that last reponse - I ran a quick test .. here is the code from that test in case it helps.

Started with this example - which has data from 0 to 10 ...
http://www.extjs.com/deploy/dev/examples/dd/dnd_grid_to_grid.html

Created this super simple renderer.


function updateCol1(val){
if (parseFloat( val ) < 2 ){
return 'x'+ val
}
return val
}


Used the renderer in the column define below:


// Column Model shortcut array
var cols = [
{ id: 'name', header: "Record Name", width: 160, sortable: true, dataIndex: 'name' },
{ header: "column1", width: 50, sortable: true, renderer: updateCol1, dataIndex: 'column1' },
{ header: "column2", width: 50, sortable: true, dataIndex: 'column2' }
];


This add an x to the first two .. but they dont change the sorting.

okwei
18 Mar 2009, 1:11 PM
Great! it works!