Automatically remove column select filter if unapplyable
authorJoey Schulze <joey@infodrom.org>
Mon, 21 Sep 2015 09:40:19 +0000 (11:40 +0200)
committerJoey Schulze <joey@infodrom.org>
Mon, 21 Sep 2015 09:40:19 +0000 (11:40 +0200)
When the filter value is stored in a cookie the filter is
automatically reapplied on page reload.  If table values have changed
in the meantime so that the original filter value is not available
anymore the LiveGrid will display 0 rows and the select filter element
will display __ALL__ (since the value it is set to is not available).

The problem could be resolved by filtering for a different value and
then resetting the filter select element back to __ALL__.  However,
since the filter already displays __ALL__ most users won't notice that
the grid is already filtered.

minsrc/ricoLiveGrid.js

index d55f345..1afb5d6 100644 (file)
@@ -872,6 +872,18 @@ Rico.LiveGridMethods = {
     var rowsElement = response.getElementsByTagName('rows')[0];\r
     var col=this.columns[parseInt(colnum,10)];
     var rows = this.buffer.dom2jstable(rowsElement);\r
+    var found = !col.filterValues || !col.filterValues.length;
+    if (!found) for (var i=0; i<rows.length; i++) {
+       if (rows[i][0] == col.filterValues[0]) {
+           found = true;
+           break;
+       }
+    }
+    if (!found) {
+       col.setUnfiltered(true);
+       if (this.options.filterHandler)
+           this.options.filterHandler();
+    }
     var c,opt,v;
     if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='EQ') v=col.filterValues[0];
     Rico.log('filterValuesUpdate: col='+colnum+' rows='+rows.length);