fixes issue 32287: Selection can be lost in P&E grids under some circumstances
authorCarlos Aristu <carlos.aristu@openbravo.com>
Fri, 19 Feb 2016 11:21:21 +0100
changeset 28620 02db9cb1d672
parent 28619 7bf022753248
child 28621 7410454ae6c6
fixes issue 32287: Selection can be lost in P&E grids under some circumstances

If we refresh the grid, after selecting a record in a page different from the first one, Smartclient internally prepares the request to retrieve the records surrounding the selected one, in order to try to keep the position of the scroll.

This behavior in P&E can cause the losing of the selected records, because they are always loaded on the first page. In order to prevent this, we detect this situation in P&E grids before performing the request, and in that case we adapt it to force the retrieval of the first page which contains all the selected records.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Fri Feb 19 10:44:55 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Fri Feb 19 11:21:21 2016 +0100
@@ -191,6 +191,14 @@
         isc.addProperties(dsRequest.originalData, me.addSelectedIDsToCriteria());
       }
       dsRequest.params[OB.Constants.IS_PICK_AND_EDIT] = true;
+      if (!me.firstRecordWillHaveValue()) {
+        // The request has been fired having scroll out of the first page
+        // We prepare startRow, endRow and localData to ensure that all the selected records will be returned from the server
+        dsRequest.startRow = 0;
+        dsRequest.endRow = me.dataPageSize;
+        me.data.localData = [];
+        me.data.setRangeLoading(dsRequest.startRow, dsRequest.endRow);
+      }
       return this.Super('transformRequest', arguments);
     };
     filterableProperties = this.getFields().findAll('canFilter', true);
@@ -629,6 +637,13 @@
     return this.data.localData && !Array.isLoading(this.data.localData[0]);
   },
 
+  firstRecordWillHaveValue: function () {
+    // localData[0] = value, a new page has been requested (scroll down)
+    // localData[0] = "loading", first page has been requested
+    // localData[0] = undefined, a grid refresh has been requested having scroll out of the first page
+    return this.data.localData[0] !== undefined;
+  },
+
   dataArrived: function (startRow, endRow) {
     var record, i, rows, selectedLen = this.selectedIds.length,
         len, savedRecord, index, j, fields, allRequiredSet;