我有一个jquery网格,顶部有一个搜索框。
Search: <input type="text" value="" id="searchInput" placeholder="Enter Document Type"/>
在搜索按键事件中,一切正常,直到用户输入不返回值的字符串。然后网格显示其通常没有找到的记录&#39;。从现在开始,搜索被破坏了。
我研究了为什么,发现postData对象/属性不再包含原始的ajax返回的网格行。因此,后续搜索会尝试过滤空网格。
此时如何强制重新加载网格(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")?databaseId=@Model.LoanIdentifier.DatabaseId&loanRecordId=@Model.LoanIdentifier.LoanId',
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"
});
}
});
}
答案 0 :(得分:0)
您可以使用:
$("#gridContactDetails").jqGrid().setGridParam({ datatype: 'local' }).trigger('reloadGrid');
OR 如果返回类型是json
$("#gridContactDetails").jqGrid().setGridParam({ datatype: 'json' }).trigger('reloadGrid');
#gridContactDetails - 更改ID