jqGrid在格式化日期搜索 [英] jqGrid searching on formatted date

查看:191
本文介绍了jqGrid在格式化日期搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的jqGrid中有一个日期列,我正在格式化。另外,我有一个工具栏搜索。我遇到的问题是当我输入数据到搜索栏来搜索格式化的日期数据时,它不会搜索格式化的日期,它可能会搜索预格式化的日期。



是否有任何方法可以搜索格式化的日期,或者在将数据插入到jqGrid之前,是否必须尝试格式化?



编辑:一些代码

  var gridLayout = [
{name:name,index:name,width: 250px},
{name:state,index:state,width:50px,hidden:true},
{name:stateName,index:stateName width:100px,hidden:true,
sorttype:function(cellValue,rowObj){
return rowObj.state;
}},
{name:stateImg,index:stateImg,width:50px,align:center,
sorttype:function(cellValue,rowObj){
return rowObj.state;
}},
{name:launchDate,index:launchDate,width:150px,sorttype:date,
formatter:'date',formatoptions:{srcformat :ISO8601Long,newformat:n / j / Y,g:i:s A}},
{name:lastWorked,index:lastWorked,width:150px,
formatter:'date',formatoptions:{srcformat:ISO8601Long,newformat:n / j / Y,g:i:s A}}
];

我在工具栏上搜索launchdate / lastworked元素,我试图搜索一个日期在newformat字段中指定的格式,但是当我这样做时,它不会回复任何数据。



运行测试后,确实以旧格式进行搜索。



编辑:



我在这里找到了一个在线示例:。



UPDATED :写完答案后,我发布了< a href =http://www.trirand.com/blog/?page_id=393/bugs/formatter-g-is-not-supported-in-local-searching/#p27070 =nofollow noreferrer>以下错误报告到trirand。我想通知所有它现在包含在jqGrid的主要代码中(请参阅 here ) 。所以下一个版本的jqGrid(版本4.4.0之后的版本)将支持格式 g 在日期。


I have a date column in my jqGrid that I am formatting. In addition, I have a toolbar search. The problem I am having is when I type in data to the search bar to search the formatted date data, it won't search the formatted date, it probably searches the pre-formatted date.

Is there any way to search the formatted date instead, or will I have to try and format it before I insert the data to the jqGrid?

Edit: Some Code

var gridLayout = [
        {name: "name", index: "name", width: "250px"},
        {name: "state", index: "state", width: "50px", hidden: true},
        {name: "stateName", index: "stateName", width: "100px", hidden: true,
            sorttype: function(cellValue, rowObj) {
                return rowObj.state;
            }},
        {name: "stateImg", index: "stateImg", width: "50px", align: "center",
            sorttype: function(cellValue, rowObj) {
                return rowObj.state;
            }},
        {name: "launchDate", index: "launchDate", width: "150px", sorttype: "date",
            formatter: 'date', formatoptions: {srcformat: "ISO8601Long", newformat:"n/j/Y, g:i:s A"}},
        {name: "lastWorked", index: "lastWorked", width: "150px",
            formatter: 'date', formatoptions: {srcformat: "ISO8601Long", newformat:"n/j/Y, g:i:s A"}}
    ];

I with the toolbar search above the launchdate/lastworked elements, I am trying to search for a date in the format specified in the "newformat" field, but it does not reply with any data when I do so.

After running a test, it does indeed search with the old format.

Edit:

I found an online example here: http://www.ok-soft-gmbh.com/jqGrid/MarkR.htm

If you enter 10/31/2007 into the date search bar and press enter, nothing appears. But if you type 2007-10-31 and press enter, the row with cell 10/31/2007 does appear in the search results. This is what I'm trying to work around.

Edit: This is jqGrid 4.4.0, jQuery 1.7.2

解决方案

jqGrid uses internal function parseDate during local searching/filtering. The implementation is very proprietary. I posted many bug fixes in the function. For example in the last one I suggested some changes to support j and n formats which you used. The bug fix is included in the current version 4.4.0 which you use.

Unfortunately the current version (4.4.0) of jqGrid still not supports the format g which you use. Only h format is currently supported. To have the format g supported one can for example include the lines

if(format[k] === 'g') {
    tsp.h = parseInt(date[k],10);
}

before the line with if(date[k] !== undefined) {.

How you can see on the demo the modified code will work:

The fixed version of jquery.jqGrid.src.js which I used in the demo you can get here.

UPDATED: After writing the answer I posted the following bug report to trirand. I wanted inform all that it's now included in the main code of jqGrid (see here). So the next version of jqGrid (the next after the version 4.4.0) will support the format g in the date.

这篇关于jqGrid在格式化日期搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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