Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:11:15+00:00 2026-06-05T12:11:15+00:00

I ‘ve two problems in jqGrid 1) Suppose there is 91 records in table

  • 0

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.
This is the Screen shot of last page
Now I am deleting the last Record
It does not redirect to 1st page

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.

Here I've given page no = 50 though max page = 1

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:11:18+00:00Added an answer on June 5, 2026 at 12:11 pm

    It’s good question! In the old answers this and this you will find the answer on your first question. Because the answers are long and you need to use delete of data on the server I repeat the same idea here.

    It’s not good to ask two separate questions inside of one question. Such questions are not good for searching engine. The users which have the problem from the part 2 of your question will be have to read unneeded information. So please don’t do this in the future.

    I start the answer with your second question. If the user type in the input part of the pager any value and press Enter the rows for the page will be requested from the server or from the local dataset. If the user choosed to large page number the grid will be successfully reloaded, but with no data. Absolutely the same results one will have in case of deleting the last row from the last page. The page with the same number will be reloaded and the user will see empty grid.

    To fix the problem one can use the following onPaging callback:

    onPaging: function (pgButton) {
        var p = this.p;
        if (pgButton === "user" && p.page > p.lastpage) {
            alert ("You can't choose the page " + $(p.pager + " input.ui-pg-input").val());
            p.page = p.currentPage; // restore the value of page parameter
            return 'stop';
        }
    },
    loadComplete: function () {
        // because on enter in the pager input the value of this.p.page
        // will be changed BEFORE calling of the onPaging the original
        // (current) page number will be overwritten. To save the problem
        // we can save somewhere the copy of the this.p.page. To be able
        // easy to maintain multiple grids on the page we can save the
        // copy as new jqGrid option:
        this.p.currentPage = this.p.page;
    }
    

    Not we go back to the first part of your question. To solve the problem one can use afterComplete callback of delGridRow method to do additional actions after the last row will be deleted. The code can be the following:

    afterComplete: function () {
        var p = this.p, newPage = p.page;
        if (p.lastpage > 1) {// on the multipage grid reload the grid
            if (p.reccount === 0 && newPage === p.lastpage) {
                // if after deliting there are no rows on the current page
                // which is the last page of the grid
                newPage--; // go to the previous page
            }
            // reload grid to make the row from the next page visable.
            $(this).trigger("reloadGrid", [{page: newPage}]);
        }
    }
    

    So we just decrease the page number in case of empty grid and reload the grid one more time.

    In case of deleting of data in the local grid (datatype: "local") one can use the following settings:

    $.extend($.jgrid.del, {
        // because I use "local" data I don't want to send the changes to the server
        // so I use "processing:true" setting and delete the row manually in onclickSubmit
        onclickSubmit: function(options, rowid) {
            var gridId = $.jgrid.jqID(this.id),
                p = this.p,
                newPage = p.page,
                $this = $(this);
    
            options.processing = true;
    
            // delete the row
            $this.jqGrid("delRowData", rowid);
            $.jgrid.hideModal("#delmod" + gridId,
                { gb: options.gbox, jqm: options.jqModal, onClose: options.onClose});
    
            if (p.lastpage > 1) {// on the multipage grid reload the grid
                if (p.reccount === 0 && newPage === p.lastpage) {
                    // if after deliting there are no rows on the current page
                    // which is the last page of the grid
                    newPage--; // go to the previous page
                }
                // reload grid to make the row from the next page visable.
                $this.trigger("reloadGrid", [{page: newPage}]);
            }
            return true;
        },
        processing: true
    });
    

    The corresponding demo you can see live here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a Octopress blog which is based on Jekyll . Now I wanted
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I was writing code for dragging mechanism which invokes to wait for small period
I've got a string that has curly quotes in it. I'd like to replace
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
This is how I get the tags of a body of text. var tags
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.