jqGrid的过滤器或按日期搜索无法正常工作的客户端 [英] jqGrid filter or search by date not working client side

查看:137
本文介绍了jqGrid的过滤器或按日期搜索无法正常工作的客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 3页。就可以了,我有我使用从Ajax调用JSON数据变成一个jqGrid的表。网格具有以下设置:

I have an ASP.NET MVC 3 page. On it, I have a table which I turn into a jqGrid using JSON data from an ajax call. The grid has the following setup:

myGrid = $('#myGrid');
myGrid.jqGrid({
    caption: 'My Grid',
    datatype: 'local',
    data: data.rows,
    height: 250,
    pager: '#myPager',
    viewrecords: true,
    colModel: [
        ...,
        {
            label: 'blah',
            name: 'blah',
            align: 'left',
            sortable: true,
            editable: false,
            width: 85,
            formatter: 'date',
            sorttype: 'date',
            datefmt: 'm/d/Y',
            formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' }
        },
        ...
    ]
});

// turn on filter toolbar
myGrid.filterToolbar();

data.rows从Ajax调用返回。这在除此之外的所有方式。我可以分页客户端,梳理客户端,以及除一个我展示colModel由各个领域的搜索。这种嗒嗒字段是日期字段,并正确显示日期,以mm / dd / yyyy格式。然而,当我在类似11/17/2010到工具栏和preSS型输入,搜索将返回0的记录。

data.rows is returned from the ajax call. This works in all ways except one. I can paginate client-side, sort client side, and search by every field except the one I show the colModel for. This 'blah' field is a date field, and it displays the dates correctly, in mm/dd/yyyy format. However, when I type in something like 11/17/2010 into the toolbar and press enter, the search returns 0 records.

所以,我深深挖成的jqGrid code,这里就是它产生它搜索前:

So I dug deep into the jqGrid code, and here's what it generates before it searches:

{"groupOp":"AND","rules":[{"field":"blah","op":"bw","data":"11/17/2010"}]}

最后,当它经过的每一行,它会评估该领域的操作中,eval(M)及和放大器; p.push(本)线,m是这样的:

Eventually, when it goes through every row and it evaluates the operation on the field, the eval(m) && p.push(this) line, m is this:

(String(this.blah).substr(0,10) == String("11/17/2010"))

基本上,它看起来对我来说,它没有认识到该领域是一个日期。它调用分析,而不是parseDate。任何人有任何想法如何解决这一问题?我知道搜索服务器端很容易,我就可以通过这个字符串,分析它和BAM。但我想,如果我能留下来的客户端。我能够在一些奥列格和汤姆竖起样品重复这一点,所以它要么一个问题或我缺少在配置的东西...

Basically, it looks to me like it's not recognizing that the field is a date. It calls parse instead of parseDate. Anybody have any ideas how to fix this? I know searching server side is easy, I can just pass that string, parse it, and bam. But I'd like to stay client side if I can. I was able to duplicate this in some of the samples that Oleg and Tom put up, so it's either an issue or I'm missing something in the configuration...

推荐答案

我觉得你的你的问题的问题从我这么有趣+1。因为您发布的行

I find your question interesting so +1 from me to your question. Because you posted the line

(String(this.blah).substr(0,10) == String("11/17/2010"))

本地搜索,我想你花太多的时间去了解当地的搜索是如何实现的过程中评估使用。因为你看,上面的线(见(字符串(this.blah).substr(0,10)... )不应当做什么(价值字符串(this.blah)将是2010-11-17,而不是11/17/2010),您可以覆盖jqGrid的相应功能(功能 _getStr 里面的 $。jgrid.from ),并修复方式的问题。

used in eval during the local searching I suppose you spend much time to understand how the local searching are implemented. Because you see that the line above (see (String(this.blah).substr(0,10) ...) is not what should be done (the value of String(this.blah) will be "2010-11-17" instead of "11/17/2010"), you can overwrite the corresponding function of jqGrid (the function _getStr inside of $.jgrid.from) and fix the problem in the way.

前段时间,我花了很多时间去prepare相应演示,这表明这种技术。该演示是ppared为<一$ P $ href=\"http://www.trirand.com/blog/?page_id=393/help/searching-on-text-field-with-accentued-chars-on-local-datas/#p21529\"相对=nofollow>在trirand论坛答案。在问题一想找到像字符串搜索的情况下,bénevise'benevise 。因此,人们必须实现真正的自定义的局部搜索。我希望信息将够你解决你说明问题。

Some time ago I spend much time to prepare the corresponding the demo, which demonstrates this technique. The demo was prepared as the answer in trirand forum. In the question one wanted to find strings like 'bénevise' in case of searching for 'benevise'. So one have to implement really custom local searching. I hope that the information will be enough for you to fix the problem which you describe.

更新时间::在我看来,我已经找到一个更简单的解决方法。你应该定义 searchoptions:{SOPT:['情商','东北']} '嗒嗒'具有数据列。然后BW(首先)将不会用于列。在等于和不等于行动在当地搜索正常工作。

UPDATED: It seems to me that I have found a much more simple workaround. You should just define searchoptions: {sopt: ['eq','ne']} for the 'blah' column having the data. Then "bw" (begin with) will not used for the column. The "equal to" and "not equal to" operations work correctly in the local searching.

更新2 这里是工作例子,我使用 SOPT 选项。

UPDATED 2: Here is the working example where I use sopt option.

这篇关于jqGrid的过滤器或按日期搜索无法正常工作的客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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