Search code examples
jqgrid

Jqgrid - Calculation of noOfPages value


I was referring to the Instant jqGrid book to set up the grid. The noOfPages attribute is calculated as follows.

//Prepare the response
$numberOfPages = ceil( $numberOfRows / $rowsPerPage );

I could see that for 581 records with rowPerPage=25, the noOfPages were appearing as 23.

System.out.println((int)Math.ceil(581/25));//23

I was expecting a value as 24 with the last page containing the records [576-581]. So here, we are missing these 6 records.


Solution

  • It seems you use Java, where ceil of two integer gives integer. I suggest you to look at this theard

    To resume the possible solutions are:

    1. int n = (int) Math.ceil((double) a / b));

    2. int n = a / b + (a % b == 0) ? 0 : 1;

    3. int n = (a + b - 1) / b;

    Select one which will meet best your requierments