cfgrid布尔列为是/否

时间:2022-05-28 10:01:00

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.

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

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...

提前致谢...

2 个解决方案

#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:

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

CF8 Ajax Grid: Renderers and Events

CF8 Ajax网格:渲染器和事件

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

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

<cfset ajaxOnLoad("init") />

Within your init() method, you would get a reference to the grid and it's ColumnModel:

在init()方法中,您将获得对网格的引用,它是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.

setRenderer方法获取列索引(从0开始)和要应用为渲染器的函数。 getIndexById()方法应该在这里工作,但你应该首先测试它,并记住,在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.

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

#2


I think it will be easier to use Decode in your database query:

我认为在数据库查询中使用Decode会更容易:

Decode(bitCol,1,'Yes','No') bitCol

#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:

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

CF8 Ajax Grid: Renderers and Events

CF8 Ajax网格:渲染器和事件

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

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

<cfset ajaxOnLoad("init") />

Within your init() method, you would get a reference to the grid and it's ColumnModel:

在init()方法中,您将获得对网格的引用,它是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.

setRenderer方法获取列索引(从0开始)和要应用为渲染器的函数。 getIndexById()方法应该在这里工作,但你应该首先测试它,并记住,在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.

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

#2


I think it will be easier to use Decode in your database query:

我认为在数据库查询中使用Decode会更容易:

Decode(bitCol,1,'Yes','No') bitCol