cfgrid boolean列为是/否 [英] cfgrid boolean column as Yes/No

查看:326
本文介绍了cfgrid boolean列为是/否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML cfgrid中有一个布尔类型列。数据作为1/0存储在数据库中,并从CF返回。我想让用户看到是/否,而不是1/0。我试过QuerySetCell,不能得到它的工作。

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>

推荐答案



< >解决方案

解决方案

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

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:呈现器和事件

,您将在网格最初呈现后通过使用ajaxOnLoad()方法调用init()方法:

Basically, you'll call your init() method after the grid has initially rendered, by using the ajaxOnLoad() method:

<cfset ajaxOnLoad("init") />



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

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
}

renderer方法,您可以应用到任何列:

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);

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

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.

大多数CF Ajax组件Ext 1.1下罩。仔细阅读 ColdFusion JavaScript函数上的Adobe文档,并记住您可以进入基础 Ext 1.1 API

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.

这篇关于cfgrid boolean列为是/否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆