0
我有一个jQuery网格与上面的搜索框。jquery网格搜索事件 - 如何强制重新加载网格
Search: <input type="text" value="" id="searchInput" placeholder="Enter Document Type"/>
在Search Keystroke事件中,一切正常,直到用户输入一个不返回值的字符串。然后网格显示其通常的'找不到记录'。从这一点开始,搜索已被打破。
我研究了为什么,发现postData对象/属性不再包含原始的ajax返回的网格行。所以后续的搜索试图针对空网格进行过滤。
如何强制重新加载我的网格在这一点(where location.reload()是)?重新加载页面不会这样做,因为这是部分页面,并强制用户回到没有网格的上一页。
<script type="text/javascript">
$(document)
.ready(function() {
'use strict';
showWebTour();
getAllAttachments();
$('#searchInput')
.on('change keyup paste',
function() {
var searchtext = $(this).val();
var grid = $('#documentList');
if ($("#documentList tr").length == 0 && searchtext.length == 0) {
location.reload();
}
var postdata = grid.jqGrid('getGridParam', 'postData');
// BUG: When Search returns no records, postData no longer exists so next search always fails
var myfilter = {
groupOp: "OR",
rules: []
};
myfilter.rules.push({
field: "DocumentType",
op: "cn",
data: searchtext
});
$.extend(postdata,
{
filters: myfilter
});
$("#gbox_documentList").show();
if ($('#empty-documentList', $('#gbox_documentList').parent()).length) {
$('#empty-documentList', $('#gbox_documentList').parent()).remove();
}
grid.jqGrid('setGridParam',
{
search: searchtext.length > 2,
postData: postdata
});
grid.trigger("reloadGrid",
[
{
page: 1
}
]);
});
});
function getAllAttachments() {
if (typeof ($('#refreshDocs') != 'undefined')) {
$('#refreshDocs').off('click');
}
$.ajax({
url:
'@Url.Action("AttactmentViewDocuments", "Document")[email protected]&[email protected]',
dataType: "json",
type: 'GET',
beforeSend: function() {
$('.all-documents-loading')
.css({
"display": "block"
});
$('.attached-documents-loading')
.css({
"display": "block"
});
$('.generated-documents-loading')
.css({
"display": "block"
});
},
success: function (data) {
bindDocumentList(data.GridData);
$('.jqgfirstrow').hide();
},
error: function(xhr, response, status) {
/* Let user know that could not load data */
},
complete: function() {
$('.all-documents-loading')
.css({
"display": "none"
});
$('.attached-documents-loading')
.css({
"display": "none"
});
$('.generated-documents-loading')
.css({
"display": "none"
});
}
});
}
可以解释如何找工作,它是从数据库生成新数据还是在客户端进行过滤侧 –