2010-03-30 71 views

回答

11

一個快速簡便的方法來做到這一點使用的jqGrid API是:

  • 呼叫editRow(這將焦點設置爲編輯行)
  • 後立即調用restoreRow(因爲你不真要編輯的行)

否則,你應該能夠使用jQuery的focus功能將焦點設置到該行,例如:jQuery("#" + row_id).focus() - 但我沒有t測試了這個方法,所以YMMV。

其實focus不會滾動網格的div。但是你可以使用下面的代碼,以保證電網滾動,使得在給定id行是可見的:

function getGridRowHeight (targetGrid) { 
    var height = null; // Default 

    try{ 
     height = jQuery(targetGrid).find('tbody').find('tr:first').outerHeight(); 
    } 
    catch(e){ 
    //catch and just suppress error 
    } 

    return height; 
} 

function scrollToRow (targetGrid, id) { 
    var rowHeight = getGridRowHeight(targetGrid) || 23; // Default height 
    var index = jQuery(targetGrid).getInd(id); 
    jQuery(targetGrid).closest(".ui-jqgrid-bdiv").scrollTop(rowHeight * index); 
} 
+0

其實,我想編輯行,所以我只是把它留在編輯模式 - 像魅力的作品! – HitLikeAHammer 2010-03-31 03:27:09

+0

謝謝賈斯汀!我應該做的唯一修改是.scrollTop((rowHeight * index)-rowHeight)使可視目標行。問候。 – nerdcoder 2011-12-14 03:48:40

-1
//i. Set newly added row (with id = newRowId) as the currently selected row 
$('#myGrid').jqGrid('setSelection', newRowId); 
//ii. Set focus on the currently selected row 
$("#" + $('#myGrid').jqGrid('getGridParam', 'selrow')).focus(); 
相關問題