Can we have 2 formatter options in jqgrid colModel ?

若如初见. 提交于 2019-12-19 09:09:09

问题


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 ?

Thanks in advance!


回答1:


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.

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.


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.

Does that help at all?


Update

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



来源:https://stackoverflow.com/questions/11080552/can-we-have-2-formatter-options-in-jqgrid-colmodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!