Parcourir la source

fixed bug in searching in TableAjax - sent request with value before last event

Piotr Labudda il y a 10 ans
Parent
commit
58aa7d1939
1 fichiers modifiés avec 19 ajouts et 16 suppressions
  1. 19 16
      SE/se-lib/TableAjax.php

+ 19 - 16
SE/se-lib/TableAjax.php

@@ -2124,16 +2124,6 @@ class TableAjax extends ViewAjax {
 			}
 		};
 
-		/**
-		 * Filters the data.
-		 */
-		priv.filter = function() {
-			if (!priv.options.filter) return;
-			if (Object.keys(_state.filters.filterCols).length == 0) return;
-
-			publ.loadPage(0);
-		};
-
 		/*
 		 sorts the data on the current sorting column
 		 */
@@ -2165,10 +2155,9 @@ class TableAjax extends ViewAjax {
 		priv.filterChanged = function(e) {
 			//clear old timer if we're typing fast enough
 			if (priv.options.debug) console.log('filterChanged L.<?php echo __LINE__; ?>');
-			/// console.log('L.<?php echo __LINE__; ?> priv.filterChanged');
 			if (_filterTimeout) {
 				clearTimeout(_filterTimeout);
-				if (priv.options.debug) console.log('filtering cancelled');
+				if (priv.options.debug) console.log('filterChanged L.<?php echo __LINE__; ?> previous filtering cancelled');
 			}
 
 			var filter = this.value
@@ -2210,12 +2199,14 @@ class TableAjax extends ViewAjax {
 				filter: filter,
 				colName: col.column
 			};
-
 			//wait a few deciseconds before filtering
-			_filterTimeout = setTimeout(function() {
-				_filterTimeout = undefined;
+			_filterTimeout = setTimeout(function(filterValue, colName) {
+				_state.filters.filterCols[colName] = {
+					filter: filterValue,
+					colName: colName
+				};
 				priv.filter();
-			}, timeout);
+			}, timeout, filter, col.column);
 		};
 
 		priv.filtersClean = function(e) {
@@ -2243,6 +2234,15 @@ class TableAjax extends ViewAjax {
 			return false;
 		},
 
+		/**
+		 * Filters the data.
+		 */
+		priv.filter = function() {
+			if (!priv.options.filter) return;
+			if (Object.keys(_state.filters.filterCols).length == 0) return;
+			priv.loadPage(0);
+		};
+
 		/**
 		 * Filters the data by specialFilter.
 		 * when: click on special filter
@@ -2991,6 +2991,9 @@ class TableAjax extends ViewAjax {
 		};
 
 		publ.loadPage = function(page, pageSize) {
+			priv.loadPage(page, pageSize);
+		}
+		priv.loadPage = function(page, pageSize) {
 			var skipCols = true, // skipCols = true - prevent columns delete
 				resetChecked = false;
 			var reqData = {