简体   繁体   English

是否需要在jquery插件的jgrid中覆盖搜索过滤器网址参数(_search)?

[英]Need to override Search Filter url param (_search) in jgrid the jquery plugin?

Hi I have created a user message page with this plugin. 嗨,我已经使用此插件创建了用户消息页面。 The grid will show the user inbox and the user outbox(sent) messages. 网格将显示用户收件箱和用户发件箱(已发送)消息。 here's a little code: 这是一些代码:

    jQuery(document).ready(function() {

       //...some stuff
       currentURL = function() {

            return 'json_member_mail.php?task='+ currentBox;
                    //where current box is either inbox or outbox
       }

       //... alot of stuff

       myGrid = jQuery("#list").jqGrid({

        url:currentURL(),
        datatype: 'json',
        mtype: 'GET',

        //      even more stuff  ....

       }).jqGrid('navGrid','#pager', 
        { 
                        the lil stuff....

            search:true,

                        //the dialog...
                 }

         // the dialog form editing whatever...

   );//grid


});//document.ready

so then when the user clicks on outbox something like this happens: 因此,当用户单击发件箱时,会发生以下情况:

jQuery("#list").jqGrid('setGridParam',{ url:currentURL(), postData:{lrt:lastReloadTime} }).trigger("reloadGrid"); //where current URL has the GET param task=outbox

it working all great until I use my search filters. 在我使用搜索过滤器之前,它都非常有效。 for example I search for the messages sent from the user 'foo' and it's all good but when I click on outbox it will still try to show me messages sent by the user 'foo' but I want the search filters to be reset. 例如,我搜索从用户“ foo”发送的消息,这一切都很好,但是当我单击发件箱时,它仍会尝试向我显示用户“ foo”发送的消息,但我希望重置搜索过滤器。

I tried loading the search dialog on document ready and closing it immediately to get the filter().reset and all that but it doesn't work :the-built-in-search-filter-box 我尝试将搜索对话框加载到准备就绪的文档中,然后立即关闭它以获取filter()。reset及其它所有方法,但它不起作用:the-built-in-search-filter-box

myGrid.trigger('reloadGrid'); myGrid.trigger('reloadGrid'); has the same behaviour as well 行为也一样

.jqGrid('setGridParam',{    url:currentURL(), postData:{_search:'false'} }).trigger("reloadGrid"); 

would fix my problem but it won't override the _search param. 可以解决我的问题,但不会覆盖_search参数。

any generous suggestions? 有什么慷慨的建议吗?

I recommend you to use no function call as avalue of the url parameter. 我建议您不要使用任何函数调用作为url参数的值。 The value of the parameter will be caclulated only once during the grid initialization. 在网格初始化期间,该参数的值仅计算一次。 Instead of that you can use 除此之外,您可以使用

url: 'json_member_mail.php',
postData: {
    task: function() {/* return currentBox based on criterias which you have */},
    lrt: lastReloadTime
}

If needed you can make the property lrt also as a function. 如果需要,可以将属性lrt也用作函数。

If some property of postData are functions the function will be called on any ajax request . 如果postData某些属性是函数,则将在任何ajax请求上调用该函数 So you can use really actual value of the currentBox on searching, paging, sorting or page reload. 因此,您可以在搜索,分页,排序或页面重新加载时使用currentBox 实际值。

If you need reload jqGrid you will no more need to change url or postData and you can just call trigger("reloadGrid") only. 如果需要重新加载jqGrid,则不再需要更改urlpostData而仅可以调用trigger("reloadGrid")

lol, So I made one of those stupid mistakes... where in the original message I say "// the dialog form editing whatever..." I made a mistake yeah I didn't even bother to write that part on here so what I had there was: 大声笑,所以我犯了一个愚蠢的错误之一...在原始消息中,我说“ //对话框形式编辑任何内容...”我犯了一个错误,是的,我什至都不想在这里写下那部分,所以我所拥有的是:

}).jqGrid('navGrid','#pager', 
        { 
            edit:false,
            add:false,
            del:false,
            search: true,
            refresh:true,
            refreshtext:"Refresh",
            searchtext:"Search"
        },
        {},//add 
        {}, //edit
        {}, //delete
            {},  <---instead of putting search options on this line
        {        <----I was putting it here on this line
            overlay:false,
            closeOnEscape:true,
                        afterShowSearch:... , 
        } /* allow the view dialog to be closed when user press ESC key*/
    );//grid

however I realized that after I fixed my problem with a hack when I saw the overlay:false was not working and there was still a jQuery UI overlay for search... 但是我意识到当我修复了hack的问题后,我看到覆盖层:false无法正常工作,并且仍然存在用于搜索的jQuery UI覆盖层...

what I did might be helpful somehow to someone who reads this one day so what I did was: 我所做的事情可能对某天读过此书的人有所帮助,所以我所做的是:

there is a get parameter nd that is a Unix Timestamp(POSIX) but in miliseconds (javascripts implementation) unlike php and mysql and most unix stuff (which is in seconds). 有一个get参数nd,它是Unix时间戳(POSIX),但以毫秒为单位(javascript的实现),与php和mysql以及大多数unix东西(以秒为单位)不同。 I also sent a timestamp of the last time any of the navigation links where clicked: 我还发送了最后一次单击任何导航链接的时间戳:

lastReloadTime = new Date().getTime() ;
jQuery("#list").jqGrid('setGridParam',{ 
        url:currentURL(), 
        postData:{lrt:lastReloadTime
} 

then in my php file that generates the json data: 然后在我的php文件中生成json数据:

$searchOK = 1;

if($_GET['_search']=='true') {

    if( isset($_GET['lrt']) ){ 

    //so here I check to see if the main mail links have been clicked at all
    //from the time of the first page load 
    //if not then its all good but if it has check for the time

        if(   (    ($_GET['nd']/1000)-($_GET['lrt']/1000)    ) < 1) $searchOK=0;
    }

    if($searchOK){ //you can do search since it might be going through pages of a search result

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM