jqGrid分页 - 没有ajax调用来获取下一页

时间:2013-07-18 19:01:18

标签: asp.net-mvc-4 jqgrid

我有一个页面,在不同的元素中有两个jqGrids。当我第一次加载页面时,Firebug报告ajax调用以获得预期的前15行,并且寻呼机准确显示页数和记录数。但是,当我单击寻呼机上的箭头时,在Firebug中没有跟踪ajax调用,因此我非常确定某些内容未正确连接。奇怪的是,我有其他只有一个jqGrid的页面,并且分页按预期工作。我的控制器(MVC4)中有断点,初始加载命中它们就好了,所有参数都是正确的:

    #region GetUnManagedMerchants
    public JsonResult GetUnManagedMerchants(string id, string sidx, string sord, int page, int rows)
    {
        return GetSomeMerchants(id, false, sidx, sord, page, rows);
    }
    #endregion

这是我的脚本代码:

$(document).ready(function () {
        jQuery("#grdUnManaged").jqGrid({
            url: '/Ajax/GetUnManagedMerchants/'  + $('#UserInContext_UserId').val(),
            datatype: 'json',
            mType: 'GET',
            colNames: ['', 'UnManaged Merchant', ''],
            colModel: [
                { name: 'Manage', key: true, index: 'manage', width: 20, sortable: false, formatter: function () { return '<img src="@Url.Content("~/content/images/icons/merchant.png")" width="16" height="16" alt="Merchants" />'; } },
                { name: 'Name', index: 'name', width: 325 },
                { name: 'id', index: 'id', width: 0, hidden: true , key: true}
            ],
            pager: '#grdUnManagedPager',
            rowNum: 15,
            width: 450,
            height: 300,
            viewrecords: true,
            caption: 'Current UnManaged Merchants',
            beforeSelectRow: function (rowid, e) {
                var iCol = $.jgrid.getCellIndex(e.target);
                if (iCol == 0) {
                    var merchantId = jQuery(this).getRowData(rowid)['id'];
                    var userId = $('#UserInContext_UserId').val();
                    ManageMerchant(userId, merchantId);
                    return true;
                }
                return false;
            }
        });
        jQuery("#grdUnManaged").jqGrid('navGrid', '#grdUnManagedPager', { add: false, edit: false, del: false, search: false, refresh: true });
    });

请帮助我解决缺少的问题!这是我在完成这个项目之前需要修复的最后一项。

谢谢!

我已经做了你建议的更改(谢谢)但是当我点击寻呼机查看后续页面时,我仍然没有收到ajax回叫。我用两个网格重新发布我的整个脚本。

    <script type="text/javascript">

    var buttonNames = {};
    buttonNames[0] = 'Manage';

    $(document).ready(function () {

        jQuery('#currentUserHeader').html('<h3>Merchant Lists for ' + $('#UserInContext_Email').val() + '.</h3>');

        jQuery("#grdManaged").jqGrid({
            url: '/Ajax/GetManagedMerchants/' + $('#UserInContext_UserId').val(),
            datatype: 'json',
            mType: 'GET',
            colNames: ['', 'Managed Merchant', ''],
            colModel: [
                { name: 'Manage', index: 'Manage', width: 20, sortable: false, formatter: function () { return '<img src="@Url.Content("~/content/images/chevron.png")" width="16" height="16" alt="Merchants" />'; } },
                { name: 'Name', index: 'Name', width: 325 },
                { name: 'id', index: 'id', width: 0, hidden: true, key: true }
            ],
            pager: '#grdManagedPager',
            rowNum: 15,
            width: 450,
            height: 300,
            viewrecords: true,
            caption: 'Current Managed Merchants',
            beforeRequest: function () {
                var getUrl = '/Ajax/GetManagedMerchants/' + $('#UserInContext_UserId').val();
                $('#grdManaged').setGridParam([{ url: getUrl }]);
            },
            beforeSelectRow: function (rowid, e) {
                var iCol = $.jgrid.getCellIndex(e.target);
                if (iCol == 0) {
                    var merchantId = jQuery(this).getRowData(rowid)['id'];
                    var userId = $('#UserInContext_UserId').val();
                    UnManageMerchant(userId, merchantId);                       
                    return true;
                }
                return false;
            }
        });
        jQuery("#grdManaged").jqGrid('navGrid', '#grdManagedPager', { add: false, edit: false, del: false, search: false, refresh: true });
    });
</script>

<script type="text/javascript">
    $(document).ready(function () {
        jQuery("#grdUnManaged").jqGrid({
            url: '/Ajax/GetUnManagedMerchants/'  + $('#UserInContext_UserId').val(),
            datatype: 'json',
            mType: 'GET',
            colNames: ['', 'UnManaged Merchant', ''],
            colModel: [
                { name: 'Manage', index: 'Manage', width: 20, sortable: false, formatter: function () { return '<img src="@Url.Content("~/content/images/chevron-left.png")" width="16" height="16" alt="Merchants" />'; } },
                { name: 'Name', index: 'Name', width: 325 },
                { name: 'id', index: 'id', width: 0, hidden: true , key: true}
            ],
            pager: '#grdUnManagedPager',
            rowNum: 15,
            width: 450,
            height: 300,
            viewrecords: true,
            caption: 'Current UnManaged Merchants',
            beforeRequest: function () {
                var getUrl = '/Ajax/GetUnManagedMerchants/'  + $('#UserInContext_UserId').val();
                $('#grdUnManaged').setGridParam([{ url: getUrl }]);
            },              
            beforeSelectRow: function (rowid, e) {
                var iCol = $.jgrid.getCellIndex(e.target);
                if (iCol == 0) {
                    var merchantId = jQuery(this).getRowData(rowid)['id'];
                    var userId = $('#UserInContext_UserId').val();
                    ManageMerchant(userId, merchantId);
                    return true;
                }
                return false;
            }
        });
        jQuery("#grdUnManaged").jqGrid('navGrid', '#grdUnManagedPager', { add: false, edit: false, del: false, search: false, refresh: true });
    });

1 个答案:

答案 0 :(得分:0)

可能是你的jqgrid相互覆盖,可能是点击分页第二个jqgrid覆盖了一些thig ,,, 但希望这有帮助.. http://www.codeproject.com/Articles/594150/MVC-Basic-Site-Step-4-jqGrid-In