0

Issue: I am sending 10 rows from server(lets assume jqgrid requests 10 rows each time).

1st fetch : 10 rows sent/displayed (id:1 to 10) View 1 - 10 of 25 in grid

2nd fetch : 10 rows sent/displayed (id:11 to 20) View 11 - 20 of 25 in grid

3rd fetch : 5 rows sent/10 rows displayed (id:21 to 25 and again 21 to 25) View 21 - 30 of 25 in grid

Attributes Set(from business layer): page=3, records=25

javascript :

<script type="text/javascript">
$(function() {
    $("#list").jqGrid({
        url : contextPath + "/getEntities",
        datatype : 'json',
        mtype : 'GET',
        jsonReader : {
            root : "response",
            page : "page",
            total : "total",
            records : "records",
            repeatitems : false

        },
        colNames : [ 'Inv No', 'Date', 'Amount', 'Tax', 'Total', 'Notes' ],
        colModel : [ {
            name : 'invid',
            width : 55,
            index : 'invid',
            sortable : true,
            sorttype : 'text',
            key : true
        }, {
            name : 'invdate',
            index : 'invdate',
            width : 90,
            sorttype : 'date',
            sortable : true
        }, {
            name : 'amount',
            index : 'amount',
            width : 80,
            align : 'right'
        }, {
            name : 'tax',
            index : 'tax',
            width : 80,
            align : 'right'
        }, {
            name : 'total',
            index : 'total',
            width : 80,
            align : 'right'
        }, {
            name : 'note',
            index : 'note',
            width : 150,
            sortable : false
        } ],
        pager : '#pager',
        rowNum : 10,
        rowList : [ 10, 20, 30 ],
        sortname : 'invid',
        sortorder : 'desc',
        viewrecords : true,
        gridview : true,
        caption : 'My first grid'
    });
});

below is the json data :

{"total":3,
"response":[
{"total":"490","amount":"500","invdate":"12-12-12","invid":"21","tax":"10","note":"OK"},
{"total":"490","amount":"500","invdate":"12-12-12","invid":"22","tax":"10","note":"OK"},
  {"total":"490","amount":"500","invdate":"12-12-12","invid":"23","tax":"10","note":"OK"},
{"total":"490","amount":"500","invdate":"12-12-12","invid":"24","tax":"10","note":"OK"},
  {"total":"490","amount":"500","invdate":"12-12-12","invid":"25","tax":"10","note":"OK"}],
"page":3,
"records":25}

NOTE : invid contains unique value in all rows, so defined as key in colModel. Also for the 3rd fetch I ma requesting 10 rows but receiving 5 from the server. Shouldn't the grid display 5 and not repeat rows as i had set repeatitems : false. Also i had set records=25 while sending json data back for display. Doesn't it mean that total records = 25. Why its showing View 21-30 of 25???

Please help...

Pravat Panda
  • 1,060
  • 2
  • 13
  • 27

1 Answers1

0

Sorry, but I can't reproduce the problem which you described. The demo displays correct results

enter image description here

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks for trying to replicate the issue. Do i have to set somewhere the no of rows I am sending to be used by the grid? – Pravat Panda May 13 '13 at 08:46
  • @PravatPanda: You are welcome! If you mean the text "View 21-25 of 25" then you should just set `records`, `total` and `page` correctly in the JSON response. You do it already correctly. [The following part of jqGrid code](https://github.com/tonytomov/jqGrid/blob/v4.4.5/js/grid.base.js#L1699-L1712) display the text. Only if you would returns wrong value of `page` property the text could be `View 21 - 30 of 25` (see [here](https://github.com/tonytomov/jqGrid/blob/v4.4.5/js/grid.base.js#L1670-L1673) too). The data which you posted are correct. – Oleg May 13 '13 at 08:58
  • thanks again...the data was duplicated while sending from server page 2 onwards, that was the error. Now I am able to implement server side pagination, its really awesome with so few lines of code. Could I ask you for a simple solution for client side sorting and displaying the grid full screen(considering screen resizing), its very small now almost occupying 25% of the screen. – Pravat Panda May 13 '13 at 11:52
  • @PravatPanda: You are welcome! I personally prefer to use `height: "auto"` and allow to user choose favorite `rowNum` from the list of values `rowList`. I save the choice in `localStorage` together with other preferences (see [here](http://stackoverflow.com/a/8436273/315935)). – Oleg May 13 '13 at 12:01