Limit the number of rows in a grid

From pmusers
Jump to: navigation, search

With PHP

To limit the number of rows in a grid with PHP, create the following trigger:

@=orderGrid = array();
for ($i = 1; $i <= 10; $i++) {
    @=myGrid[$i] = array();
}

Where "orderGrid" is the variable associated with the grid.

Set this trigger to fire before the DynaForm which holds the grid. Then, uncheck the option in the grid's properties to add rows. That way the user can delete rows, but can't add any.

With JavaScript

The grid.onAddRow() method can be used limit the number of rows in a grid with JavaScript:

$("#orderGrid").onAddRow( function(aNewRow, oGrid, rowIndex) {
  console.log(rowIndex);
  if (rowIndex > 10) {
    $("#orderGrid").deleteRow(rowIndex);
    alert("No more than 10 rows are allowed.");
  }
});

Where the ID of the grid is "orderGrid".