I 've two problems in jqGrid
1) Suppose there is 91 records in table with rownum set to 10, now when i navigate to last page and delete the record number 91, it does not reload the grid automatically, when i use ReloadGrid explicitly it went to reload the whole data from controller which increases the network load.
2) In my grid there are 10 pages and when I enter the page number greater than the max page in text box it gives the blank grid, ideally it should dispaly some message.
any solution?
ADDED CODE FOR BETTER UNDERSTANDING OF PROBLEM
$(document).ready(function () {
$('#jqgCars').jqGrid({
//url from wich data should be requested
url: '@Url.Action("CarsListing", "Car")?Carid=' + getID(),
//event for inline edit
onSelectRow: function (currentSelectedRow) {
if (currentSelectedRow && currentSelectedRow != $.lastSelectedRow) {
//save changes in row
$('#jqgCars').jqGrid('saveRow', $.lastSelectedRow, false);
$.lastSelectedRow = currentSelectedRow;
}
},
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: ['ID','Number','Name'],
//columns model
colModel: [
{ name: 'ID', index: 'ID', align: 'left', editable: false },
{ name: 'Number', index: 'Number', align: 'left', editable: true, formatter: "text", edittype: 'text', editrules: { required: true}, editoptions:{maxlength:"25"}},
{ name: 'Name', index: 'Name', align: 'left', editable: true, formatter: "text", edittype: 'text', editrules: { required: false} , editoptions:{size:"35",maxlength:"255"}},
],
//pager for grid
pager: $('#jqgpCars'),
//number of rows per page
rowNum: 2,
//initial sorting column
sortname: 'name',
//initial sorting direction
sortorder: 'asc',
//display total records count
viewrecords: true,
//grid height
height: '100%'
});
$('#jqgCars').jqGrid('navGrid', '#jqgpCars', { add: true, del: true, edit: true, search: false });
$('#jqgCars').jqGrid('hideCol', "ID");
$('#jqgCars').setGridWidth(600 , true);
var dialogPosition = $(this).offset();
});
UPDATE -- SOLUTION
Solution to problem#1
$.extend($.jgrid.del, {
afterComplete: function () {
var p = $('#jqgCars')[0].p;
var newPage = p.page; // Gets the current page
if (p.reccount === 0 && newPage > p.lastpage && newPage > 1) {
// if after deleting there are no rows on the current page and lastpage != firstpage than
newPage--; // go to the previous page
}
// reload grid to make the row from the next page visable.
$(p.pager + " input.ui-pg-input").val(newPage); //Here setting the new page into textbox before loading in case of longer grid it would look nice
$('#jqgCars').trigger("reloadGrid", [{page: newPage}]); // reloading grid to previous page
}
});
Solution of problem#2 is exact as posted by Oleg
This works fine with jqGrid v4.1.2