cfgrid 布尔列为是/否

发布于 2024-07-19 17:39:15 字数 427 浏览 2 评论 0原文

我在 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>

提前致谢...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末骤雨初歇 2024-07-26 17:39:16

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

CF8 Ajax 网格:渲染器和事件

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

<cfset ajaxOnLoad("init") />

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

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

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

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

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

gridCM.setRenderer(cm.getIndexById('myColumnName'), yesNoRenderer);

: setRenderer 方法采用列索引(从 0 开始)和要用作渲染器的函数。 getIndexById() 方法应该在这里起作用,但您应该首先测试它以确保确定,并记住大小写在 JavaScript 中很重要。

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

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.

薄荷港 2024-07-26 17:39:16

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

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

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

Decode(bitCol,1,'Yes','No') bitCol
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文