Fixes bug 29838: Prevents unlimited datasource requests when filtering the grid
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 11 May 2015 10:53:02 +0200
changeset 26693 f1124f44f626
parent 26692 5c24b3086d32
child 26694 eb03fd0d3bd2
Fixes bug 29838: Prevents unlimited datasource requests when filtering the grid

The problem was that the logic to check that if a datasource request was triggered by scrolling up in a grid that did not have its initial rows loaded (see [1]) did not work well when the user filtered the grid after having scrolled down the grid till loading its second page. This caused the totalRows property of the grid to be miscalculated, and this triggered the undefinite amount of datasource requests.

The logic to check if the request was triggered by scrolling up has been changed. Now, instead of checking low-level smartclient properties like lastScrollTop, we check if there are rows loaded in the positions just after the page that was just received. Only in that case we want to prevent resetting the totalRows property of the ResultSet with the value returned by the datasource.

[1] https://code.openbravo.com/erp/devel/pi/rev/c51dce7e9fd3c47915464ab4f565a9d1cee60e3b
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	Fri May 08 14:02:09 2015 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Mon May 11 10:53:02 2015 +0200
@@ -238,8 +238,7 @@
     },
 
     transformData: function (newData, dsResponse) {
-      var i, length, timeFields, responseToFilter, responseToSort = false,
-          newTotalRows;
+      var i, length, timeFields, responseToFilter, newTotalRows;
 
       // when the data is received from the datasource, time fields are formatted in UTC time. They have to be converted to local time
       if (dsResponse && dsResponse.context && (dsResponse.context.operationType === 'fetch' || dsResponse.context.operationType === 'update' || dsResponse.context.operationType === 'add')) {
@@ -260,10 +259,6 @@
         responseToFilter = true;
       }
 
-      if (dsResponse.context && dsResponse.context._dsRequest && dsResponse.context._dsRequest.params && dsResponse.context._dsRequest.params.isSorting) {
-        responseToSort = true;
-      }
-
       if (this.localData && !responseToFilter) {
         length = this.localData.length;
         newTotalRows = dsResponse.totalRows;
@@ -282,11 +277,11 @@
           // increase one to request additional page to backend
         }
 
-        // detects if the request was issued due to having scrolled up
-        // this does not apply when the grid has just been sorted, as the previous local data is discarded
-        if (!responseToSort && this.grid.body.lastScrollTop !== undefined && this.grid.body.lastScrollTop > this.grid.body.getScrollTop()) {
-          // in that case, set the totalRows of the response to the length of the localData, to avoid
-          // setting the totalRows of the grid to an invalid value
+        // detects if the request was issued due to having scrolled up.
+        // in that case, set the totalRows of the response to the length of the localData, to avoid
+        // setting the totalRows of the grid to an invalid value
+        // to confirm if this is the case, we check if there are rows loaded after the page that was just received
+        if (this.rowIsLoaded(dsResponse.endRow + 1)) {
           dsResponse.totalRows = this.localData.length;
         }