问题
I have a boolean type column in an html cfgrid. The data is stored in the database as 1/0 and is returned from CF as such. I want the user to see Yes/No instead of 1/0. I tried QuerySetCell, and couldn't get it to work.
The form is editable, when you double click the cell, the checkboxes show and it updates as it should. The only issue is the display.
<cfform>
<cfgrid name="blah" format="html" bind="mycfccall" selectmode="edit">
<cfgridcolumn name="bitCol" header="Is it" width="75" type="boolean">
</cfgrid>
</cfform>
Thanks in advance...
回答1:
You'll need to apply a custom field renderer. You'll need to add an init() js function to your page, along with a renderer method. I have the basic process of applying a custom renderer on my blog:
CF8 Ajax Grid: Renderers and Events
Basically, you'll call your init() method after the grid has initially rendered, by using the ajaxOnLoad() method:
<cfset ajaxOnLoad("init") />
Within your init() method, you would get a reference to the grid and it's ColumnModel:
init = function() {
var myGrid = ColdFusion.Grid.getGridObject('myGridID');
var gridCM = myGrid.getColumnModel();
// The rest goes here
}
You'll also need your renderer method, that you can apply to any column:
yesNoRenderer = function(value,meta,record,row,column,store) {
if (value === 1){
return "Yes";
} else {
return "No";
}
}
After which, you'll need to apply the renderer to the column of your choice:
gridCM.setRenderer(cm.getIndexById('myColumnName'), yesNoRenderer);
The setRenderer method takes the column index (starting from 0) and the function to apply as a renderer. The getIndexById() method should work here, but you should test it first to be sure, and remember that casing is important in JavaScript.
Most of the CF Ajax components use Ext 1.1 under the hood. Carefully read through The Adobe documentation on the ColdFusion JavaScript Functions, and remember that you can tap into the underlying Ext 1.1 API.
回答2:
I think it will be easier to use Decode in your database query:
Decode(bitCol,1,'Yes','No') bitCol
来源:https://stackoverflow.com/questions/884474/cfgrid-boolean-column-as-yes-no