title: Pass custom filter to SmartTable
body: <p>I created a custom control on a smart filter bar. I am unsure of how to pass the selection to the server so it updates the filter and rebinds the data to the smart table. Here is the custom smartfilter bar:</p>
  
  <pre><code>&lt;smartFilterBar:ControlConfiguration groupId="_BASIC" key="ZQ_STAT" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="false" &gt;
  &lt;smartFilterBar:customControl&gt;
   &lt;Select id="qualStatusDropDown" change="onQualSearch"&gt;
      &lt;core:Item key="" text=" " /&gt;
      &lt;core:Item key="0" text="0" /&gt;
      &lt;core:Item key="1" text="ONE" /&gt;
      &lt;core:Item key="2" text="TWO" /&gt;
      &lt;core:Item key="3" text="THREE" /&gt;
  &lt;/Select&gt;
  &lt;/smartFilterBar:customControl&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the code I am using in the controller:</p>
  
  <pre><code>onQualSearch : function (oEvent) {
  var oTableSearchState = [];
  var sQuery = oEvent.getSource().getProperty("selectedKey");
  oTableSearchState = [new Filter("ZQ_STAT", FilterOperator.EQ, sQuery)];
  this._applyFilter(oTableSearchState);
  //MessageToast.show("You picked " + sQuery);
  },
  
  _applyFilter: function(oTableSearchState) {
   var oTable = this.byId("gSmartTable");
   //oTable.getBinding("items").filter(oTableSearchState, "Application");
  }
  </code></pre>
  
  <p>I used this code on a standard table and search field, but I am getting an error in the console stating 'getBinding' is undefined. If I output the 'oTable' object to the console, I can see that the 'items' aggregation does exist, though I am thinking maybe I am not calling the correct aggregation. I have spent some time trying to determine how to even get what the current table binding is, though it's always blank. I am using 'enableAutoBinding=true' on the table, and when I disable it and output that property to the console, it is still always blank, even after I apply a filter search. </p>
  
  <p>When I use one of the other fields available, which is just a standard smartfilter, I can see the oData call in the network tab modifies the query and adds the 'filter' to the query. This:</p>
  
  <pre><code>/Employees?$skip=0&amp;$top=20&amp;$select=Pernr,STEXT_2,Butxt,STLTX,ZQ_STAT
  </code></pre>
  
  <p>vs this (after filter):</p>
  
  <pre><code>/Employees?$skip=0&amp;$top=20&amp;$filter=(Butxt eq 'XXXXX')&amp;$select=Pernr,STEXT_2,Butxt,STLTX,ZQ_STAT
  </code></pre>
  
  <p>I'm sure I am missing something simple, or I am just going about this wrong. Can anyone assist with what to do next?</p>
  
  <p>EDIT: I am getting a bit closer with this. After viewing this example:</p>
  
  <p><a href="https://sapui5.hana.ondemand.com/sdk/#docs/guide/3a515829ffd74239878ebc0d453d001d.html" rel="nofollow noreferrer">Add Additional Filter Logic</a></p>
  
  <p>I realized the binding parameters only exist in the 'beforeRebindTable' event. I add that event to the control and updated my script:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>onQualSearch : function (oEvent) {
   var oSmartTable = this.byId("gSmartTable");
   oSmartTable.rebindTable();
   //oSmartTable.showOverlay();
  },
    
  
   onBeforeRebindTable : function(oEvent) {
   // Get bindinParams Object, which includes filters
   var oBindingParams = oEvent.getParameter("bindingParams");
   // Create the aFilters array
   var aFilters = oBindingParams.filters;
   // Create the table object
   var oSmartTable = oEvent.getSource();
   // Get the SmartFilterBarID
   var oSmartFilterBar = this.byId(oSmartTable.getSmartFilterId());
    if (oSmartFilterBar instanceof sap.ui.comp.smartfilterbar.SmartFilterBar) {
     var oCustomControl = oSmartFilterBar.getControlByKey("ZQ_STAT");
         if (oCustomControl instanceof sap.m.Select) {
       var sQualStat = oCustomControl.getSelectedKey();
       oBindingParams.filters.push(new sap.ui.model.Filter("ZQ_STAT", "EQ", sQualStat));
      }
     }
   },</code></pre>
  </div>
  </div>
  </p>
  
  <p>The only issue now is the overlay does not seem to be working; the filtered data is there on the table, but it's greyed out. I added the '.showOverlay();' function, which properly displays the filtered data, but then I get an error in the console that 'showOverlay' is not a function. It doesn't appear in the prototype (I logged the oSmartTable object), except as '_showOverlay'. I tried running that function as well, and it gives no error, though it does not display the overlay.</p>
  
  <p>I'm sure it's something simple, any help would be appreciated.</p>
  
  <p>Cheers!</p>
  
  <p>EDIT 2: I think I pretty much have this answered due to to my understanding of how this works now.  </p>
  
  <p>If a user puts some text in any of the other fields on the smart filter bar, they must hit enter or the 'Go' button for the filter to actually run. This is the same for the dropdown list. For some reason, I thought I would be able to automatically rebind and refresh the table listing once the item in the dropdown is selected. While I can use the 'rebindTable();' function to reset the table binding, it won't display the new data in the non-greyed-out state until I hit 'Go' or enter. So, from a user perspective, and for consistency sake, if I leave out the 'onQualSearch' event, then the dropdown just acts like any of the other fields in the SmartFilterBar- the user enters/selects input, and hits the 'Go' button or the enter key.</p>
  
  <p>I also incorrectly identified 'showOverlay()' as a function, when it's actually an event, so that's why I could not just call 'oSmartTable.showOverlay();'. I may also have used the incorrect nomenclature, identifying the 'overlay' as the greyed-out vs non-greyed-out state of the table data. This is what I am referring to: </p>
  
  <p><a href="https://i.stack.imgur.com/FBhYi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FBhYi.png" alt="Greyed Out"></a></p>
  
  <p>vs</p>
  
  <p><a href="https://i.stack.imgur.com/73oXw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/73oXw.png" alt="Not Greyed Out"></a></p>
  
  <p>I'll chalk this up to a learning experience, both this SAPUI5 as well as general Javascript, as both are fairly new to me. Sorry if this caused any confusion.</p>
  
  <p>By all means, if anyone knows a way to make the table display the data immediately upon change, please add comments/suggestions!</p>
  
  <p>Hopefully this post at least helps someone else out who is trying to do a similar thing! </p>