1

I using jqGrid v4.4.5.When the grid is empty , show 'Page 1 of 0'.I read this answer but my problem is not solved.My httphandler send this json result

"{\"page\":0,\"records\":0,\"rows\":[],\"total\":0,\"userdata\":null}"

 gridParaf = $("#gridParaf").jqGrid(
    {
        url:"GetLetterInformationHandler.ashx?CurrentUser=" + 1457,
        datatype: 'json',
        width: $("#contentParaf").width() + 410,
        height: $("#contentParaf").height() - 20,
        direction: "rtl",
        colNames: ['IAnsDateTime', 'IAnsState'],
        colModel: [
            { name: 'IAnsDateTime', width: 50, sortable: false, hidden: false, template: CenterTemplate },
            { name: 'IAnsState', width: 20, sortable: false, hidden: false, template: CenterTemplate },
        ],
        rowNum: 20,
        loadonce: true,
        rowList: [5, 10, 20],
        recordpos: "left",
        ignoreCase: true,
        toppager: true,
        viewrecords: true,
        sortorder: "desc",
        scrollOffset: 1,
        editurl: 'clientArray',
        shrinkToFit: true,
        jsonReader:
        {
            repeatitems: false,
        },
        gridview: true,
    });

enter image description here

Community
  • 1
  • 1
ZSH
  • 631
  • 5
  • 16
  • 36

2 Answers2

2

I suppose that the correct JSON response is

{"page":0,"records":0,"rows":[],"total":0,"userdata":null}

and just the debugger display you the response in the format

"{\"page\":0,\"records\":0,\"rows\":[],\"total\":0,\"userdata\":null}"

In the case you can try to use the following jsonReader

jsonReader: {
    repeatitems: false,
    page: function (obj) {
        return obj.page !== undefined && obj.page !== 0 ? obj.page : "0";
    }
}

I hope it will solve your problem. See more information in the answer.

UPDATED: Because you use loadonce: true you should define both jsonReader and localReader in the same way

jsonReader: {
    page: function (obj) {
        return obj.page !== undefined && obj.page !== 0 ? obj.page : "0";
    }
},
localReader: {
    page: function (obj) {
        return obj.page !== undefined && obj.page !== 0 ? obj.page : "0";
    }
}

See the demo.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Tanks but not work :(.Why when reload grid,grid pass pageindex=1 to server?I think that i have problem because pageindex is 1.I calculate other information in server "total = (Count + 0 - 1) / 10" "records = Count" "total =(int)Math.Ceiling((float)objectList.Count /(float)numberOfRows);" – ZSH Jul 22 '13 at 13:10
  • @ZSH: You have to define `localReader` additional to `jsonReader` because you use `loadonce: true`. See **UPDATED** part of my answer. – Oleg Jul 22 '13 at 13:41
  • 1
    I define both jsonReader and localReader but not work and i set loadonce:false but not work.If i set value of pageIndex in server,obj.page in jsonReder return my value({"page":"1","records":"0","rows":[],"total":"0","userdata":null}) but if remove value of pageIndex(in json result)always return null.I'm confused and do not know what to do – ZSH Jul 23 '13 at 07:02
  • 1
    @ZSH: Sorry, but I don't understand what you mean under `pageIndex`. I don't understand too why you need to return `{"page":"1","records":"0","rows":[],"total":"0","userdata":null}` from the server. Do you tried [the demo](http://www.ok-soft-gmbh.com/jqGrid/empty2.htm) from **UPDATED** part of my answer? What is difference from your code and my? In general you *do can* use `loadonce: true` and just implement `jsonReader` and `localReader` with `page` defined as function. It's important that the function return **string** `"0"` in case when you want display "Page **0** from 0". – Oleg Jul 23 '13 at 07:14
  • I remove page in json result and add only jsonReader and loadonce: true now it's work fine :-).Tanks Oleg – ZSH Jul 23 '13 at 07:45
0

Change your jsonReader: like this and try

jsonReader: { repeatitems: false, root: function (obj) {
                        var JSONObject = JSON.parse(obj);

                        return JSONObject["rows"];
                    }, page: function (obj) {
                        var JSONObject = JSON.parse(obj);
                        return JSONObject["page"];

                    }, total: function (obj) {
                        var JSONObject = JSON.parse(obj);
                        return JSONObject["total"];

                    },
                        records: function (obj) {

                            var JSONObject = JSON.parse(obj);

                            return JSONObject["records"];

                        }
                    }
Xavier
  • 1,672
  • 5
  • 27
  • 46