jqGrid“_search” URL 中未设置参数

发布于 2024-11-16 19:21:16 字数 1315 浏览 4 评论 0 原文

我有以下代码:

$("#perform_search").click(function() {    
  var postdata = $("#translationsList").jqGrid('getGridParam','postData');
  postdata._search = true;
  postdata.searchString = $("#auto_complete_search").val();
  console.log('postdata._search: ' + postdata._search);
  jQuery("#translationsList").trigger("reloadGrid", [{page:1}]);
});

当我单击 ID 为 perform_search 的按钮时,生成的 URL 如下,并且从具有 id 的文本字段中提取值 searchString=hello auto_complete_search

[域名]/translations_feed.php?language_cd=EN&_search=false&nd=1308754288459&rows=20&page=1&sidx=phrase& ;sord=asc&searchString=hello

...并且应该发生的是 URL 字符串有_search=true,但正如您从示例 URL 中看到的,传递的值是 _search=false 注意:第 5 行,我在其中将 postdata._search 的值输出到控制台,控制台按预期显示 postdata._search: true,因此看起来按预期工作。

似乎所有其他参数都很好地通过了。

更新

看来,如果我第一次使用内置搜索按钮(jqGrid 中的小放大镜图标),那就正确设置了“_search=true”参数 - 之后我的按钮就可以正常工作了。不确定两者之间的联系是什么,但本质上似乎我的参数仍然被忽略。例如,如果我通过放大镜进行搜索,并更改我的 JavaScript,以便第 5 行读取 postdata._search = false 它会传递 _search=true (换句话说) ,第 5 行似乎被完全忽略)。

想知道我是否只是在 postdata 上设置了错误的变量

I have the following code:

$("#perform_search").click(function() {    
  var postdata = $("#translationsList").jqGrid('getGridParam','postData');
  postdata._search = true;
  postdata.searchString = $("#auto_complete_search").val();
  console.log('postdata._search: ' + postdata._search);
  jQuery("#translationsList").trigger("reloadGrid", [{page:1}]);
});

When I click on the button with ID perform_search the resulting URL is below, and the value searchString=hello is pulled from a text field with an id of auto_complete_search:

[domainname]/translations_feed.php?language_cd=EN&_search=false&nd=1308754288459&rows=20&page=1&sidx=phrase&sord=asc&searchString=hello

... and what's supposed to happen is that the URL string has _search=true, but as you can see from the sample URL, the value being passed is _search=false NOTE: line 5, where I output the value of postdata._search to the console, the console shows postdata._search: true as expected, so that appears to be working as expected.

Seems like all other params are passing through just fine.

UPDATE

Seems that, if I first use the built-in search button (the little magnifying glass icon in jqGrid), that is sets the "_search=true" param correctly - and after that my button works fine. Not sure what the connection between to the two is, but essentially it seems as if my param is still being ignored either way. For example, if I do a search via the magnifying glass, and change my javascript so that LINE 5 reads postdata._search = false it passes _search=true (in other words, LINE 5 seems to be ignored completely).

Wondering if I'm simply setting the wrong variable on postdata

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身狗的梦 2024-11-23 19:21:16

我已经回答了封闭式问题 就像你的问题一样。问题是您应该在 jqGrid 本身上设置 search 参数,而不是尝试以这种方式更改 postData。

换句话说,要将 _search 设置为 true,您应该将 jqGrid 的 search 参数设置为 true 并且不设置任何直接使用 postData 的属性。同样,您不应设置 postDatapage 参数。请改用 rowNum 参数。

所以,你的代码应该更简单:

$("#perform_search").click(function() {    
  $("#translationsList").jqGrid('setGridParam', { search: true, postData: { searchString:$("#auto_complete_search").val() } });
  jQuery("#translationsList").trigger("reloadGrid", [{page:1}]);
});

I answered an already closed question like yours. The problem is that you should be setting the search parameter on the jqGrid itself, and not trying to alter the postData in this way.

In other words, to set _search as true you should set search parameter of jqGrid to true and not set any properties of postData directly. Similarly, you should not set page parameter of postData. Instead use the rowNum parameter.

So, your code should be much simpler:

$("#perform_search").click(function() {    
  $("#translationsList").jqGrid('setGridParam', { search: true, postData: { searchString:$("#auto_complete_search").val() } });
  jQuery("#translationsList").trigger("reloadGrid", [{page:1}]);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文