jqGrid内联导航器未初始化

jqGrid inline navigator not initializing

本文关键字:初始化 导航 jqGrid      更新时间:2023-09-26

我试图在jqGrid上初始化内联导航器。使用4.4.0版本。代码:

$('#line-items-grid').jqGrid({
    caption      : '',
    width        : 704,
    shrinkToFit  : 1,
    forceFit     : true,
    scrollOffset : 0,
    url          : '',
    datatype     : 'local',
    rowNum       : 20,
    viewrecords  : true,
    height       : 'auto',
    gridview     : true,
    autoencode   : true,
    pager        : '#line-items-pager',
    colModel     : [
        {label: 'Commodity',  name: 'contract_material', sortable: false, width: 99, cellattr: word_wrap, editable: true,  classes: 'line-item-contract-material', edittype: "select"},
        {label: 'Date',       name: 'date',              sortable: false, width: 77, cellattr: word_wrap, editable: true,  classes: 'line-item-date', editoptions: {
            dataInit: function (el) {
                $(el).datepicker();
            }
        }},
        {label: 'Vendor',     name: 'vendor',            sortable: false, width: 95, cellattr: word_wrap, editable: true,  classes: 'line-item-vendor', editoptions: {maxlength: "50"}},
        {label: 'Ticket/PO#', name: 'ticket_po_num',     sortable: false, width: 66, cellattr: word_wrap, editable: true,  classes: 'line-item-ticket-po-num', editoptions: {maxlength: "50"}},
        {label: 'Lbs',        name: 'lbs',               sortable: false, width: 73, cellattr: word_wrap, editable: true,  classes: 'line-item-lbs'},
        {label: 'Units',      name: 'units',             sortable: false, width: 49, cellattr: word_wrap, editable: true,  classes: 'line-item-units'},
        {label: 'Rate/Ton',   name: 'rate_per_ton',      sortable: false, width: 64, cellattr: word_wrap, editable: true,  classes: 'line-item-rate-per-ton'},
        {label: 'Rate/Unit',  name: 'rate_per_unit',     sortable: false, width: 64, cellattr: word_wrap, editable: true,  classes: 'line-item-rate-per-unit'},
        {label: 'Total',      name: 'total',             sortable: false, width: 72, cellattr: word_wrap, editable: true, classes: 'line-item-total'}
    ],
    jsonReader   : {
        repeatitems: false
    },
    onSelectRow  : function (id) {
        if (id && id !== lastsel) {
            $('#line-items-grid').jqGrid('restoreRow', lastsel);
            $('#line-items-grid').jqGrid('editRow', id,
                {
                    keys: true,
                    extraparam: {
                        reporting_period_id: function () { return $('#reporting_period_filter').val(); },
                        pickup_id: function () { return $('#pickup_filter').val(); },
                        lbs_per_ton: function () { return material_lbs_per_ton[$('#line-items-grid tr#' + id).find('td.line-item-contract-material select').val()]; }
                    },
                    oneditfunc: lineItemEditPrep,
                    aftersavefunc: lineItemSuccess,
                    errorfunc: lineItemError,
                    afterrestorefunc: function () { $('.qtip').qtip('destroy'); },
                    restoreAfterError: false
                });
            //clear out error messages
            $('.qtip').qtip('destroy');
            lastsel = id;
        }
    },
    gridComplete : lineItemViewPrep,
    editurl      : "line_items/line_item_edit"
});
$('#line-items-grid').jqGrid('navGrid', '#line-items-pager', {
    add: false,
    edit: false,
    del: false
});
$('#line-items-grid').jqGrid('inlineNav', '#line-items-pager');

显示了常规导航器(视图和刷新)的按钮,但内联导航器没有按钮。我错过了什么?

(旁注,如果它是相关的:我设置url和数据类型选项在一个单独的函数加载数据到网格。)

我建议您使用jqGrid的最新版本。目前的版本是4.4.5。在jqGrid 4.4.0和4.4.5之间修复了许多错误。

你描述的问题已经在jqGrid 4.4.1中修复了。如果你真的需要使用旧的4.4.0,那么你应该修复navButtonAdd方法内部的行(它在jquery.jqGrid.src.js中有行号8796)

if( p.id && $("#"+$.jgrid.jqID(p.id), findnav).html() !== null )  {return;}

if( p.id && $("#"+$.jgrid.jqID(p.id), findnav)[0] !== undefined )  {return;}

将原始演示结果与使用上述修复的相同代码进行比较。