cfgrid布尔列为是/否

Gen*_*e R 3 coldfusion boolean cfgrid cfgridcolumn

我在html cfgrid中有一个布尔类型列.数据以1/0的形式存储在数据库中,并从CF返回.我希望用户看到是/否而不是1/0.我试过QuerySetCell,但无法让它工作.

表单是可编辑的,当您双击单元格时,复选框显示并按预期更新.唯一的问题是显示器.

<cfform>
   <cfgrid name="blah" format="html" bind="mycfccall" selectmode="edit">
      <cfgridcolumn name="bitCol" header="Is it" width="75" type="boolean">
   </cfgrid>
</cfform>
Run Code Online (Sandbox Code Playgroud)

提前致谢...

Ste*_*des 6

您需要应用自定义字段渲染器.您需要向页面添加init()js函数以及渲染器方法.我有在我的博客上应用自定义渲染器的基本过程:

CF8 Ajax网格:渲染器和事件

基本上,在网格最初渲染之后,您将使用ajaxOnLoad()方法调用init()方法:

<cfset ajaxOnLoad("init") />
Run Code Online (Sandbox Code Playgroud)

在init()方法中,您将获得对网格的引用,它是ColumnModel:

init = function() {
    var myGrid = ColdFusion.Grid.getGridObject('myGridID');
    var gridCM = myGrid.getColumnModel();
    // The rest goes here
}
Run Code Online (Sandbox Code Playgroud)

您还需要可以应用于任何列的渲染器方法:

yesNoRenderer = function(value,meta,record,row,column,store) {
    if (value === 1){
        return "Yes";
    } else {
        return "No";
    }
}
Run Code Online (Sandbox Code Playgroud)

之后,您需要将渲染器应用于您选择的列:

gridCM.setRenderer(cm.getIndexById('myColumnName'), yesNoRenderer);
Run Code Online (Sandbox Code Playgroud)

setRenderer方法获取列索引(从0开始)和要应用为渲染器的函数.getIndexById()方法应该在这里工作,但你应该首先测试它,并记住,在JavaScript中,外壳很重要.

大多数CF Ajax组件都使用Ext 1.1.仔细阅读关于ColdFusion JavaScript函数的Adobe文档,并记住您可以使用底层的Ext 1.1 API.