当计数超过~9000时,jqgrid不显示任何结果

时间:2015-03-11 07:10:47

标签: asp.net-mvc jqgrid mvcjqgrid

我正在使用带有MVC4的jqgrid版本4.1.2,使用loadonce选项。当搜索结果的计数超过大约9000条记录时,网格上不会显示任何数据。

可能是什么问题?

以下是JS代码:更新1

function showCompletedGrid() {
// Set up the jquery grid
$("#jqTableCompleted").jqGrid({
    // Ajax related configurations
    url: jqDataUrl,
    datatype: "json",
    mtype: "POST",
    loadonce: true,
    loadtext: 'Loading Data please wait ...',


    postData: { strUserName: function () { return $('#ddlUserName :selected').val(); },
        strFunctionName: function () { return $('#ddlOPMSFunction :selected').text(); },
        strProcName: function () { return $('#ddlOPMSProcess :selected').text(); },
        strCategory: function () { return $('#ddlSearchCategory :selected').text(); },
        strWorkType: function () { return $('#ddlSearchWorkType :selected').text(); },
        strRequestNumber: function () { return $('#txtRequestNo').val(); },
        strStatus: function () { return $('#ddlSearchStatus :selected').text(); },
        strFromDate: function () { return $('#txtFromDate').val().toString(); }, //datepicker('getDate'),
        strToDate: function () { return $('#txtToDate').val().toString(); }, //datepicker('getDate'),
        strAction: "Closed"
    },
    autowidth: true,
    shrinkToFit: true,
    // Specify the column names
    colNames: ["S.No.", "User Name", "Category", "Work Type", "Request Number", "Status", "Time Spent", "RE", "GUID", "Marked for Correction", "Correction Complete", "Reason", "Task Type", "acf2id", "Created Date", "Action", "IsTeam"],

    // Configure the columns
    colModel: [
                { name: "SNo", index: "SNo", sorttype: 'int', width: 100, align: "left", hidden: true, sortable: true, search: true, searchoptions: { sopt: ['eq']} },
                { name: "UserName", index: "UserName", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "Category", index: "Category", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "WorkType", index: "WorkType", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "RequestNumber", index: "RequestNumber", width: 200, align: "left", sortable: true, search: true, searchoptions: { sopt: ['cn']} },
                { name: "Status", index: "Status", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "TimeSpent", index: "TimeSpent", width: 200, align: "left", sortable: true, search: true },
                { name: "RE", index: "RE", width: 200, align: "left", sortable: true, search: true },
                { name: "GUID", index: "GUID", sortable: false, search: false, width: 200, align: "left", hidden: true },
                { name: "MarkCorrection", index: "MarkCorrection", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "CorrectionComplete", index: "CorrectionComplete", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "Reason", index: "Reason", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "TaskType", index: "TaskType", width: 200, align: "left", sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "acf2id", index: "acf2id", width: 200, align: "left", hidden: true, sortable: true, search: true, sorttype: 'string', searchoptions: { sopt: ['cn']} },
                { name: "CreatedDate", index: "CreatedDate", width: 200, align: "left", hidden: false, search: false },
                { name: 'Actions', sortable: false, search: false, fixed: true, align: 'center', formatter: returnHyperLinkCompleted },
                { name: 'IsTeam', sortable: false, hidden: true, search: false, fixed: true, align: 'center' }
              ],
    ignoreCase: true,
    //width: 1250,
    height: 150,

    // Paging
    toppager: true,
    pager: $("#jqTableCompletedPager"),
    //rowTotal: 200,
    rowNum: 20,
    rowList: [20, 15, 10, 5],
    viewrecords: true,
    emptyrecords: "",
    hiddengrid: true,

    // Default sorting
    sortname: "SNo",
    sortorder: "asc",

    // Grid caption
    caption: "Closed",
    loadComplete: function (data) {

        var RE;
        var TimeSpent;
        var rowIDs = jQuery("#jqTableCompleted").jqGrid('getDataIDs');
        for (var i = 0; i < rowIDs.length; i++) {
            var rowID = rowIDs[i];
            var row = jQuery('#jqTableCompleted').jqGrid('getRowData', rowID);

            RE = hmsToSecondsOnly(row.RE);
            RE = (0.2 * RE) + RE;
            TimeSpent = hmsToSecondsOnly(row.TimeSpent);
            if (TimeSpent > RE && RE > 0) {
                $(row).removeClass('ui-widget-content');
                $(row).removeClass('ui-state-highlight');
                $("#jqTableCompleted tr[id='" + rowID + "']").addClass('myColor');

            }
        }
    }
}).navGrid("#jqTableCompletedPager",
        { refresh: true, add: false, edit: false, del: false },
            {}, // settings for edit
            {}, // settings for add
            {}, // settings for delete
            {sopt: ["cn"]}
     );

$("#jqTableCompleted").jqGrid('navGrid', '#jqTableCompletedPager', { del: false, add: false, edit: false, search: false });
$("#jqTableCompleted").jqGrid('filterToolbar', { searchOnEnter: false, searchOperators: true });

$("#jqTableCompleted").jqGrid('navButtonAdd', '#jqTableCompletedPager',
{ caption: "Export to Excel", buttonicon: "ui-icon-extlink", title: "Export", id: "btnExport",
    onClickButton: function (evt) {
        var UserName = $('#ddlUserName option:selected').val();
        var RequestNumber = $('#txtRequestNo').val();
        var FunctionName = encodeURIComponent($('#ddlOPMSFunction option:selected').text());
        var ProcessName = encodeURIComponent($('#ddlOPMSProcess option:selected').text());
        var Category = $('#ddlSearchCategory option:selected').text();
        var WorkTypeName = $('#ddlSearchWorkType option:selected').text();
        var SearchStatus = $('#ddlSearchStatus option:selected').text();
        var TransactionStartTS = $('#txtFromDate').val().toString();
        var TransactionEndTS = $('#txtToDate').val().toString();

        window.open("../Search/Export?UserName=" + UserName + "&RequestNumber=" + RequestNumber + "&FunctionName=" + FunctionName + "&ProcessName=" + ProcessName + "&Category=" + Category + "&WorkTypeName=" + WorkTypeName + "&SearchStatus=" + SearchStatus + "&TransactionStartTS=" + TransactionStartTS + "&TransactionEndTS=" + TransactionEndTS + "&ActionName=" + "Closed");
    }
});

}

虽然从控制器返回数据并且格式正确,但如下所示,网格不会显示任何结果。

var jsonData = new
            {
                page = page,
                rows = data
            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);

使用loadonce选项从服务器返回所有数据时,是否对浏览器的数量或依赖性有任何限制?

非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

最后,我通过在Fiddler中跟踪请求找到了上述问题的解决方案,在响应标题中显示了以下错误:

  

使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过maxJsonLength属性上设置的值。

在搜索上述错误后,我找到了一个解决方法: Here

基本上问题区域不是jqGrid,而是 JavaScriptSerializer MaxJsonLength 属性,默认为2097152个字符~4 MB数据。资料来源:MaxJsonLength

为了使它工作,我在Action方法中替换了以下代码:

return Json(jsonData, JsonRequestBehavior.AllowGet);

使用:

var jsonResult = Json(jsonData, JsonRequestBehavior.AllowGet);
            jsonResult.MaxJsonLength = int.MaxValue;
            return jsonResult;

感谢。