jqgrid colModel中可以有2个格式化程序选项吗? [英] Can we have 2 formatter options in jqgrid colModel ?

查看:38
本文介绍了jqgrid colModel中可以有2个格式化程序选项吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jqgrid,其中有一个自定义格式器,用于"column1".我需要将"column1"排序为日期.我知道我可以给出"formatter:date",如果我给出这个,我的自定义格式化程序将无法正常工作.我们可以有2个格式化程序吗,或者还有其他选择吗?

I have a jqgrid, where it has a custom formatter to "column1". I need to sort the "column1" as date. I know that i can give "formatter:date", if i give this, my custom formatter does not work. Can we have 2 formatters or is there any other option for this ?

提前谢谢!

推荐答案

不,尽管自定义格式器可以执行任何操作,包括根据基础数据的值调用多个格式器,但每个字段只能有一个格式器.在任何情况下,格式化程序都可用于控制数据的显示方式,但它不应影响行的排序方式.

No, you can only have one formatter per field, although a custom formatter can do anything including calling multiple formatters depending upon the value of the underlying data. In any case, the formatter is used to control how the data is displayed, but it should not affect how the rows are sorted.

如果使用的是本地数据,则可以使用sorttype选项来确定数据行的排序方式.排序基于单元格的实际值;您可以自由使用自定义格式化程序来执行所需的任何格式化.

If you are using local data, you can use the sorttype option to determine how a row of data is sorted. The sorting is based on the actual value of the cell; you are free to use a custom formatter to do whatever formatting is required.

或者,如果您正在对服务器端进行排序,我认为您仍然可以使用相同的方法.只需定义所需的任何自定义格式化程序,然后使用该列的基础日期值进行排序即可.

Alternatively, if you are doing sorting server-side, I think you can still use the same approach. Just define whatever custom formatter you need, and then sort using the underlying date value of the column.


您还应该知道,有一个 unformat 选项,该选项可在使用自定义格式化程序时用于检索原始数据.我认为您在这里不需要它,但是想提一下它,以防万一您需要使用它.


You should also be aware that there is an unformat option that can be used to retrieve the original data when using a custom formatter. I don't think you need it here, but wanted to mention it just-in-case you need to use it.

这有帮助吗?


更新

要从自定义格式器功能调用日期格式器,首先需要在colmodel中设置适当的选项:

To call the date formatter from your custom formatter function, you first need to set the appropriate options in your colmodel:

formatoptions: { srcformat:'m/d/Y', newformat:'ShortDate' },

然后,您可以像在自定义格式化程序中一样,调用日期格式化程序,就像其他任何函数一样:

Then you can call the date formatter just like any other function, from within your custom formatter:

function myFormatter (cellvalue, options, rowObject) {
    return $.fn.fmatter.date(cellvalue, options, rowObject);
}

以上内容应该可以工作,尽管我尚未对其进行测试.请让我知道怎么回事...

The above should work, although I have not tested it. Please let me know how it goes...

这篇关于jqgrid colModel中可以有2个格式化程序选项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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