PDA

View Full Version : Grid related question?



businessman332211
17 Jul 2008, 9:51 AM
If I was getting a value for the grid (for example a number) is there a way to do a test on the number BEFORE showing whatever was needed for teh record. I need to see if the number is below 0 then I need to show a link if not then I need to show nothing?
Is there a way to do that with the grid. I am already seeing the value coming through into the grid I just need to do a test on it and if it's above 0 then I need to show a link there.....and if not then just show a blank field (with nothing in it) or something. Is there a way to perform this test inside the grid? Thanks again?

businessman332211
17 Jul 2008, 10:18 AM
Here is an example of what I am trying to do. I am getting the data. I just want to "Simple" print out here the value hello everywhere in that cell..just to get this part working. It also seems I can use fn.data to get access to the data in that cell coming from the database?
Does anyone see what I am doing wrong here?



var column_model = new Ext.grid.ColumnModel ([
{id: 'u_id', header: "User ID", width: 140, sortable: true, dataIndex: 'u_id'},
{id: 'login_name', header: "Login Name", width: 150, sortable: true, dataIndex: 'login_name'},
{id: 'first_name', header: "First Name", width: 100, sortable: true, dataIndex: 'first_name'},
{id: 'last_name', header: "Last Name", width: 100, sortable: true, dataIndex: 'last_name'},
{id: 'group_name', header: "Group", width: 200, sortable: true, dataIndex: 'group'},
{id: 'subarea', header: "Subarea", width: 250, sortable: true, dataIndex: 'subarea'},
{id: 'report_to', header: "Report To", width: 200, sortable: true, dataIndex: 'report_to'},
{id: 'city', header: "City", width: 150, sortable: true, dataIndex: 'city'},
{id: 'CodeNumber', header: 'Code Number', width: 150, sortable: true, dataIndex: 'CodeNumber', renderer: function(col, fn) {
value: 'Hello'
}}
]);

businessman332211
17 Jul 2008, 10:29 AM
This is the new code I have. This should work based on putting stuff together from the API? Is there something wrong with it?



var column_model = new Ext.grid.ColumnModel ([
{id: 'u_id', header: "User ID", width: 140, sortable: true, dataIndex: 'u_id'},
{id: 'login_name', header: "Login Name", width: 150, sortable: true, dataIndex: 'login_name'},
{id: 'first_name', header: "First Name", width: 100, sortable: true, dataIndex: 'first_name'},
{id: 'last_name', header: "Last Name", width: 100, sortable: true, dataIndex: 'last_name'},
{id: 'group_name', header: "Group", width: 200, sortable: true, dataIndex: 'group'},
{id: 'subarea', header: "Subarea", width: 250, sortable: true, dataIndex: 'subarea'},
{id: 'report_to', header: "Report To", width: 200, sortable: true, dataIndex: 'report_to'},
{id: 'city', header: "City", width: 150, sortable: true, dataIndex: 'city'},
{id: 'HasForecast', header: 'Has Forecast', width: 150, sortable: true, dataIndex: 'HasForecast', renderer: test(col, fn) {
if (fn.data < 0) {
fn.metadata.attr = 'Yes';
}else {
fn.metadata.attr = 'No';
}
}}
]);

businessman332211
17 Jul 2008, 10:39 AM
Well I forgot one thing..below is the new code?The error that is being returned is that metadata is null or not an object...but that's listed inside the API as a viable object. Am I calling it wrong or something?
var column_model = new Ext.grid.ColumnModel ([ {id: 'u_id', header: "User ID", width: 140, sortable: true, dataIndex: 'u_id'}, {id: 'login_name', header: "Login Name", width: 150, sortable: true, dataIndex: 'login_name'}, {id: 'first_name', header: "First Name", width: 100, sortable: true, dataIndex: 'first_name'}, {id: 'last_name', header: "Last Name", width: 100, sortable: true, dataIndex: 'last_name'}, {id: 'group_name', header: "Group", width: 200, sortable: true, dataIndex: 'group'}, {id: 'subarea', header: "Subarea", width: 250, sortable: true, dataIndex: 'subarea'}, {id: 'report_to', header: "Report To", width: 200, sortable: true, dataIndex: 'report_to'}, {id: 'city', header: "City", width: 150, sortable: true, dataIndex: 'city'}, {id: 'HasForecast', header: 'Has Forecast', width: 150, sortable: true, dataIndex: 'HasForecast', renderer: function test(col, fn) { if (fn.data < 0) { fn.metadata.attr = 'Yes'; }else { fn.metadata.attr = 'No'; } }} ]);

devnull
17 Jul 2008, 11:28 AM
you arent reading the API docs correctly. Look at the setRenderer method of ColumnModel and make sure to expand it. the args that are passed to the renderer function are listed.