cfgrid 布尔列为是/否
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要应用自定义字段渲染器。 您需要将 init() js 函数以及渲染器方法添加到您的页面。 我在博客上应用自定义渲染器的基本过程:
CF8 Ajax 网格:渲染器和事件
基本上,您将在网格初始渲染后通过使用 ajaxOnLoad() 方法调用 init() 方法:
在 init() 中方法,您将获得对网格及其 ColumnModel 的引用:
您还需要渲染器方法,可以将其应用于任何列:
之后,您需要将渲染器应用于您选择的列
: setRenderer 方法采用列索引(从 0 开始)和要用作渲染器的函数。 getIndexById() 方法应该在这里起作用,但您应该首先测试它以确保确定,并记住大小写在 JavaScript 中很重要。
大多数 CF Ajax 组件在底层都使用 Ext 1.1。 仔细阅读有关 ColdFusion JavaScript 函数 的 Adobe 文档,并记住您可以利用底层的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:
Within your init() method, you would get a reference to the grid and it's ColumnModel:
You'll also need your renderer method, that you can apply to any column:
After which, you'll need to apply the renderer to the column of your choice:
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.
我认为在数据库查询中使用 Decode 会更容易:
I think it will be easier to use Decode in your database query: