Meraj
Meraj

Reputation: 426

How to add empty rows to the JQGrid

I have the grid with paging. Every page has max 10 rows. if i have 3 records only i need to show 7 empty rows,

like excel sheet layout

Like this:

enter image description here

I got the solution :

loadComplete: function (data) {
                var pagesize = jQuery("#list5").jqGrid('getGridParam', 'rowNum');
                if (data.rows.length < pagesize) {
                    for (i = 0; i < pagesize - data.rows.length; i++) {
                        $("#list5").addRowData(i + 1, {});
                    }
                }
            }

If any other efficient solution is there then please let me know.

Upvotes: 1

Views: 7069

Answers (1)

Paul Newman
Paul Newman

Reputation: 46

The problem with that is the page counts at the lower right are wrong: they include the blank rows. E.g. "View 91 to 100" when there are only 95 rows. Here's a solution to that:

loadComplete: function (data) {
  var grid = jQuery("#list5"),
    pageSize = parseInt(grid.jqGrid("getGridParam", "rowNum")),
    emptyRows = pageSize - data.rows.length;

  if (emptyRows > 0) {
    for (var i = 1; i <= emptyRows; i++)
        // Send rowId as undefined to force jqGrid to generate random rowId
        grid.jqGrid('addRowData', undefined, {});

    // adjust the counts at lower right
    grid.jqGrid("setGridParam", {
      reccount: grid.jqGrid("getGridParam", "reccount") - emptyRows,
      records: grid.jqGrid("getGridParam", "records") - emptyRows
    });
    grid[0].updatepager();
  }
}

Upvotes: 2

Related Questions