2
  1. Below code is my JQGRID code, am using JsonReader to bind data in grid. Also find the image posted below.

2.My service response is JSON, so am using JSON Reader, if I change to "localReader", data not binding.

This is my JQgrid pager, even though, if there is no data, the pager shows 1 of 0.

jQuery(document).ready(function () {
        $("#datagrid").jqGrid({
            url: service url,
            ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
            type: "GET",
            datatype: "json",
            colNames:['Id','MID','Status','VendorID','VendorName','InvoiceNo','DocDate','Amount','DocNo','Type','DueDate','ClDoc','Text','UserName','Currency','ConCode','Region','Stat','Process','Comb','Comments'],
            colModel:[
    {name:'id',index:'id', width:50,sortable:true},
    {name:'mid',index:'mid', width:50, sortable:true},
    {name:'status',index:'status', width:70, sortable:true},
    {name:'vendorid',index:'vendorid', width:90, sortable:false,align:"left"},
    {name:'vendorname',index:'vendorname', width:170, sortable:false,align:"left"},
    {name:'invoiceno',index:'invoiceno', width:130, sortable:false,align:"left"},   
    {name:'docdate',index:'docdate', width:100, sortable:false},
    {name:'amount',index:'amount', width:80, sortable:false,align:"Right"},
    {name:'docno',index:'docno', width:100, sortable:false},
    {name:'typee',index:'typee', width:50, sortable:false},
    {name:'duedate',index:'duedate', width:100, sortable:false},
    {name:'cldoc',index:'cldoc', width:80, sortable:false},
    {name:'text',index:'texxt', width:70, sortable:false},
    {name:'username',index:'username', width:100, sortable:false},
    {name:'currency',index:'currency', width:80, sortable:false},
    {name:'concode',index:'concode', width:80, sortable:false},
    {name:'region',index:'region', width:70, sortable:false},
    {name:'stat',index:'stat', width:60, sortable:false},
    {name:'process',index:'process', width:60, sortable:false},
    {name:'combination',index:'combination', width:60, sortable:true},
    {name:'comments',index:'comments', width:150, height:20, edittype:'textarea', sortable:false, editable: true,
            editoptions: {disabled: false, size:50, resizable:true}}
    ],

    jsonReader: {
        repeatitems: false,        // To Bind the Data in Grid.
        id: "id",
        root: function (obj) { return obj; },        // To Bind the Data in Grid.
        page: function () { return 1; },
        total: function () { return 1; },
        records: function (obj) { return obj.length; },
         subgrid: {
            root: "rows",
            cell: "cell",
            repeatitems: false,                        // To Bind the Data in SubGrid.
            id: "id",
            root: function (obj) { return obj; }       // To Bind the Data in SubGrid.
            }
    },

            rowNum:20,
            rowList:[20,30,40,50],
            loadonce: true,       // If True, all pages will be loaded, else only 1 page will be displayed.
            pager: '#navGrid',
            sortable: true,
            sortname: 'mid',
            viewrecords: true,
            showOn: 'button',
            multiselect:true,   // Enabling Checkbox.       
            sortorder: 'asc', 
            //prmNames: {rows: 'max'},
            prmNames: {rows: 'max', search: null},
            height: 290,
            width: 1222,
            shrinkToFit: false,            // For Horizontal Scrollbar.
            toolbar: [true,"bottom"],      // For appending Buttons in Toolbar.
            rownumbers: true             // To display No.of rows.
        });
    });
Lakshmana Kumar D
  • 2,205
  • 1
  • 13
  • 10
  • Why do u want to use localReader ?? – jsduniya Jun 21 '13 at 05:53
  • 1
    why because, chk this link, they had given a alternate solution for that jqgrid pager, if your data is placed in localReader. http://stackoverflow.com/questions/16678783/in-the-paging-footer-arent-the-page-1-of-0-suppose-to-say-page-0-of-0 – Lakshmana Kumar D Jun 21 '13 at 06:22

1 Answers1

3

You've referenced correct answer which could play additional role for the problem. I suppose that you use already the latest version of jqGrid with described fix.

I think that the origin of your problem is very simple. The option jsonReader which you use contains page property defined as

page: function () { return 1; }

It means that it souls be displayed page number 1 even if the response from the server contains empty array. I think that you should change the code to the following

page: function (obj) { return obj.length > 0 ? 1 : 0; }

or to

page: function (obj) { return obj.length > 0 ? "1" : "0"; }
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks. It is working... page: function (obj) { return obj.length > 0 ? 1 : 0; } – Lakshmana Kumar D Jun 24 '13 at 06:27
  • Maybe a newer version of jQuery, but the above didn't work for me. I had to tell it to look at Rows and return the current Page if it passed -->page: function (obj) { return obj.Rows.length > 0 ? obj.Page : "0"; } – ASeale Apr 28 '15 at 21:11
  • @ASeale: It's very important *which version of jqGrid you use*, which value have `datatype` and if it's `"json"` or `"xml"` then whether you use `loadonce: true`. – Oleg Apr 28 '15 at 21:43
  • @Oleg Sorry for the delay. I am using jqGrid v4.8.2, JSON data, and no I do not use loadonce: true. – ASeale Aug 12 '15 at 20:51
  • @ASeale: It's better if you post separate question where you include more details about the problem and about what you do. The demo, which demonstrates the problem, would be very helpful. – Oleg Aug 12 '15 at 20:55