# HG changeset patch
# User Augusto Mauch <augusto.mauch@openbravo.com>
# Date 1362573708 -3600
# Node ID fc9ac2bd3dd4af2154c87b0175e464ea8514df3e
# Parent  1cb8e112f36fdc4435be569d8cc476f5c35adf11
Fixes issue 23211: Fixes adding rows in a grid with many existing rows

The behaviour of the addition of rows in the grid now mimics the behavior of the creation of records in the form view:
- If not all records are cached in the grid, the record is added in the first position
- If all records are cached in the grid, the record is added in the last position.

diff --git a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
@@ -2534,7 +2534,11 @@
     if (rowNum === undef) {
       // nothing selected
       if (!this.getSelectedRecord()) {
-        insertRow = this.getTotalRows();
+        if (this.getTotalRows() > this.data.cachedRows) {
+          insertRow = 0;
+        } else {
+          insertRow = this.getTotalRows();
+        }
       } else {
         insertRow = 1 + this.getRecordIndex(this.getSelectedRecord());
       }
