无法在JQgrid中加载超过20

时间:2016-08-09 06:40:28

标签: javascript jquery jqgrid

我正在开发一个mvc3项目asp.net。这是我在JQgrid中的数据控制器中的代码

public JsonResult LeaveCancel(string sidx, string sord, int page, int rows, int LeaveHeaderId, DateTime Sdate, DateTime EndDate, int isCheckAll)
    {
        DateTime strtDate = Sdate;
        DateTime Startdate = strtDate.AddDays(1);
        DateTime endDate = EndDate;
        DateTime _startCntDate = Sdate;
        TimeSpan difference;
        difference = endDate - strtDate;
        if (isCheckAll == 0)
        {
            var leavedtl = (from ld in db.LeaveDetails where ld.LeaveHeaderId == LeaveHeaderId select ld).Distinct();
            int countLeaveDetails = (from ld in db.LeaveDetails where ld.LeaveHeaderId == LeaveHeaderId select ld).GroupBy(x => x.TranDate).Count();               
            var rowsObj = new object[countLeaveDetails];
            int rowId = 0;
            foreach (LeaveDetail leave in leavedtl)
            {
                int leavedtlId = leave.LeaveDetailId;
                if ((strtDate.DayOfWeek != DayOfWeek.Saturday || strtDate.DayOfWeek != DayOfWeek.Sunday) && Startdate != leave.TranDate)
                {
                    rowsObj[rowId] = new { id = rowId, cell = new object[] { rowId, leavedtlId, false, leave.TranDate.Value.ToShortDateString(), leave.TranDate.Value.DayOfWeek.ToString()} };
                    rowId++;
                    Startdate = leave.TranDate.Value;
                }
                strtDate = strtDate.AddDays(1);
            }
 var a = rowsObj.Skip((page - 1) * rows).Take(rows);
            var result = new JsonResult();
            result.Data = new
            {
                totalRecords = rowId,
                total = (int)Math.Ceiling((float)rowsObj.Count() / (float)rows),
                page = page,
                records = a.Count(),
                rows = a
            };
            return result;
        }

}

这是我的jqgrid的代码

function LeaveCancel(LeaveHeaderId, Sdate, EndDate) {
    var isCheckAll = 0;
    var url1 = URL
    $("#LeaveCancelDataEntryList").jqGrid({
        url: url1,
        datatype: 'json',
        mtype: 'POST',
        colNames: ['RowId', 'leavedtlId', 'Is Cancel?', 'Date', 'Day'],
        colModel: [
                { name: 'rowId', index: 'rowId', hidden: true, editable: true, sortable: false, width: 80, align: 'left' },
                { name: 'leavedtlId', index: 'leavedtlId', hidden: true, editable: false, sortable: false, width: 80, align: 'left' },
               //{name: 'cbox_leave_cancel', index: 'cbox_leave_cancel', editable: true, formatter: "checkbox", edittype: 'checkbox', editoptions: { value: "True:False" }, sortable: false, width: 95, align: 'center' },
                  {name: 'cbox_leave_cancel', index: 'cbox_leave_cancel', editable: true, formatter: "checkbox", formatoptions: { disabled: false }, edittype: 'checkbox', editoptions: { value: True:False"
                   },
                   sortable: false,
                   width: 95,
                   align: 'center'
               }, 
                { name: 'LStartDate', index: 'LStartDate', editable: false, sortable: false, width: 70, align: 'left' },
                { name: 'LDate', index: 'LDate', editable: false, sortable: false, width: 70, align: 'left' }
          ],
        pager: $('#LeaveCancelDataEntryPager'),
        rowNum: 5,
        rowList: [5, 15, 20],
        //pgbuttons: true,
        //            recordtext: '',
        //            pgtext: '',
        //            loadonce: true,
        sortname: '',
        sortorder: '',
        viewrecords: true,
        imgpath: '/Content/themes/redmond/images/',
        height: '100%',
        loadComplete: function (result) {
            var ids = jQuery("#LeaveCancelDataEntryList").getDataIDs();
            var len = ids.length, newLine;
            if (len < 5) {
                AddNewRowToGrid(len, "#LeaveCancelDataEntryList");
            }
            CancelDayrowsObj = getCheckStateCancel(result.totalRecords);
            saveCancel = true;
            $("#LeaveCancelDataEntryPager").css("width", "auto");
            $("#LeaveCancelDataEntryPager .ui-paging-info").css("display", "none");
            for (var i = 0; i < len; i++) {
                var lastSel;
                var objRowData = jQuery("#LeaveCancelDataEntryList");
                if (ids && ids !== lastSel) {
                    objRowData.jqGrid('restoreRow', lastSel);
                    objRowData.saveRow(lastSel, true, 'clientArray');
                    objRowData.jqGrid('restoreRow', lastSel);
                    objRowData.jqGrid('editRow', i, true, null, null, 'clientArray');
                }
            }
        }
    });
    return false;
}

因为我的jqgrid上方的标题无法从上面的20/21加载数据。例如,我有25个数据。因此,我需要选择20 per page + next page来获取25数据。但在我的问题,当我点击下一个按钮/下一个导航按钮,它只加载和加载和加载。请参阅此picture,但当我尝试加载5 per page时,下一个按钮正在运行,直到它到达5/5并再次加载。

0 个答案:

没有答案