I have a jqGrid on a page and users can click a button to add a new row. If there are already enough rows on the page to fill the visible portion of the grid the new row is added and a scroll bar appears but the user needs to scroll to see the new row.
Is there a way to do this programmatically?
jqGrid exposes a property rowNum where you can set the number of rows to display for each page.
Rows can be selected in ParamQuery Grid either by user action or programmatically. All rows can be selected using Ctrl - A or Cmd - A (Mac).
You can select or highlight rows based on data using the queryCellInfo event or can also select a row using an external button click event. The queryCellInfo is triggered every time a request is made to access particular cell information, element and data.
jqxGrid('getrowid', selectedrowindex); var commit = $("#jqxgrid"). jqxGrid('deleterow', id); $("#popupWindow"). jqxWindow('hide'); } }); $("#cancel"). click(function () { $("#popupWindow").
A quick and easy way to do this using the jqGrid API is to:
editRow
(which will set focus to the edited row)restoreRow
(because you do not really want to edit the row)Otherwise you should be able to use jQuery's focus
function to set focus to the row, for example: jQuery("#" + row_id).focus()
- but I have not tested this method, so YMMV.
Actually focus
will not scroll the grid's div. But you can use the following code to guarantee that the grid scrolls such that the row with a given id
is viewable:
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);
}
//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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With