jqGrid 4.0 bindKeys方法使用向上和向下箭头键移动整个网格

时间:2011-11-12 18:39:52

标签: javascript jquery jqgrid

我正在使用jqGrid 4.0并遇到问题。

这是我的JavaScript代码:

$grid.jqGrid({
    url:'parties-process.php?action=SELECT',
    datatype: "json",
    colNames:['Party ID', 'Party Name', 'Balance', 'Opening Balance', 'Opening Debit', 'Options'],
    colModel:[
        {name:'partyID',index:'partyID', width:55},
        {name:'partyName',index:'partyName', width:150},
        {name:'balance',index:'balance', width:50, align:'right'},
        {name:'opening',index:'opening', hidden:true},
        {name:'openingdr',index:'openingdr', hidden:true},
        {name:'act',index:'act', width:150, sortable:false, align:'center', hidden:true}
    ],
    scroll: true,
    autowidth: true,
    height: myLayout.panes.center.outerHeight()-183,
    pager: jQuery('#pager'),
    rowNum:999,
    rowList:[10,20,30],
    sortname: 'partyID',
    viewrecords: true,
    sortorder: "desc",
    caption: "Parties",
    gridComplete: function(){
        var data = $grid.jqGrid('getDataIDs');
        for(var i=0;i < data.length;i++){
            var id = data[i];
            editbtn = "<small><a class=\"editbtn\" onclick=\"edit('"+id+"');\">Edit</a></small> ";
            deletebtn = "<small><a class=\"deletebtn\" onclick=\"del('"+id+"');\">Delete</a></small>";
            $grid.jqGrid('setRowData',data[i],{act:editbtn+deletebtn});
        }
        $(".editbtn").button({
            icons: { primary: "ui-icon-pencil" },
            text: false
        });
        $(".deletebtn").button({
            icons: { primary: "ui-icon-close" },
            text: false
        });
    }
}).jqGrid('bindKeys');
问题是,当我按向上和向下箭头键时,选择了相应的行,bt它还会滚动整个网格。

1 个答案:

答案 0 :(得分:2)

我这样做是为了解决问题:

$(grid).bind('keydown', function (e) {
  if (e.keyCode == 38 || e.keyCode == 40) e.preventDefault();
});