jqGrid使用工具栏搜索格式化的日期 [英] jqGrid search formated date using toolbar

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

问题描述

希望有人可以帮助您解决问题.我有一个项目,用户必须能够设置日期格式,以了解他在jqGrid中看到日期的方式(这是我最近开始学习的),并且还必须实现工具栏搜索.现在我有这个:

       {
            name: 'DueDate',
            formatter: "date",
            formatoptions: {
                srcformat: 'd.m.Y',
                newformat: gridOptions.dateFormat, // setting date format
            },
            sorttype: 'date',
            searchoptions: {
                sopt: ['eq'],
                dataInit: function (e) {
                    //setting jquery-ui extension: multi-datepicker
                }
            }
        },

问题在于,可能的格式选择之一必须是j.F,其中系统仅显示日期和完整的月份名称,而不显示年份.当日期格式设置为这种特定格式时,即使我知道存在这样的日期,也无法在工具栏搜索中找到它.格式化本身效果很好,它是寻找引起问题的日期的方法.即使使用这种格式(实际上是任何格式)在工具栏字段中输入日期,也不会显示任何结果.我可以通过将newformat设置为任何其他格式来添加它,工具栏搜索可以工作,但不能与此j.F

一起使用

系统使用jqGrid JS-v5.2.1

P.S.我想知道是否可以在显示j.F

时使用d.m.Y格式进行过滤

解决方案

问题:当日期从srcformat格式化为newformat时,将根据规则将年份削减.当输入仅包含月份和日期的搜索日期时,将缺少年份,并且将对不包含年份的原始数据执行搜索(因为转换为原始日期).这会导致错误的搜索结果.例如,如果您输入4.July作为搜索字符串,则根据规则,此字符串将转换为4.7.1970,并在该日期之前执行搜索,这不会得到期望的结果.

解决方案:一种可行的解决方案是定义一个虚拟字段,其中包含格式化数据,并且在执行搜索时,不应将其应用于实际日期字段,而应将其应用于新版本, ed虚拟字段.下面是代码:

{
    name: 'DueDate',
    index : 'mydate',
    formatter: "date",
    formatoptions: {
        srcformat: 'd.m.Y',
        newformat: gridOptions.dateFormat, // setting date format
    },
    sorttype: 'date',
    searchoptions: {
        sopt: ['eq'],
        dataInit: function (e) {
            //setting jquery-ui extension: multi-datepicker
        }
    }
},
{
    name : 'mydate',
    hidden: true,
    jsonmap : function(item) {
        return  $.jgrid.parseDate.call($("#jqGrid")[0] , 'd.m.Y', item.DueDate , 'j.F'); 
    }
},

请注意DueDate中的index属性. #jqGrid是mydate虚拟字段中jsonmap中定义的网格的ID

hope somebody can help with a solution to a problem. I have a project where user must be able to set the date format on how he sees the date in jqGrid (which I started to learn recently) and also a toolbar search must be implemented. Right now i have this:

       {
            name: 'DueDate',
            formatter: "date",
            formatoptions: {
                srcformat: 'd.m.Y',
                newformat: gridOptions.dateFormat, // setting date format
            },
            sorttype: 'date',
            searchoptions: {
                sopt: ['eq'],
                dataInit: function (e) {
                    //setting jquery-ui extension: multi-datepicker
                }
            }
        },

The problem lies in the fact, that one of the possible format choices must be j.F, where system shows only date and full month name, but no year. When date format is set to this particular format, toolbar search can't find it, even though I know such a date exists. Formatting itself works well, it is the search for a date that causes problems. Even typing date in toolbar field using this format (any-format actually), doesn't show any results. I might add that by setting newformat to any other format, toolbar search works, but not with this j.F

System uses jqGrid JS - v5.2.1

P.S. I wonder if it is possible to filter using d.m.Y format, while displaying j.F

解决方案

The problem: When the date is formatted from srcformat to the newformat a year is cut-ed according to the rules. When a search date is entered which contain only month and day the year is missing and the search is performed on the original data without year (since the conversion to original date). This causes the wrong searching results. Example if you enter 4.July as search string then according to the rules this string is converted to 4.7.1970 and search is performed to this date, which give not the desired results.

The solution: One possible solution is to define a virtual field which contain the formatted data and when a search is performed it should be applied not the the actual date field, but to the new build-ed virtual field. Below is the code:

{
    name: 'DueDate',
    index : 'mydate',
    formatter: "date",
    formatoptions: {
        srcformat: 'd.m.Y',
        newformat: gridOptions.dateFormat, // setting date format
    },
    sorttype: 'date',
    searchoptions: {
        sopt: ['eq'],
        dataInit: function (e) {
            //setting jquery-ui extension: multi-datepicker
        }
    }
},
{
    name : 'mydate',
    hidden: true,
    jsonmap : function(item) {
        return  $.jgrid.parseDate.call($("#jqGrid")[0] , 'd.m.Y', item.DueDate , 'j.F'); 
    }
},

Note the index property in DueDate. The #jqGrid is the id of the grid in definition in jsonmap in mydate virtual field

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

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