cancel
Showing results for 
Search instead for 
Did you mean: 

SmartTable Filter

Former Member
0 Kudos

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:

<smartFilterBar:ControlConfiguration groupId="_BASIC" key="ZQ_STAT" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="false" >
	<smartFilterBar:customControl>
	 <Select id="qualStatusDropDown" change="onQualSearch">
		<core:Item key="" text=" " />
		<core:Item key="0" text="0" />
		<core:Item key="1" text="ONE" />
		<core:Item key="2" text="TWO" />
		<core:Item key="3" text="THREE" />
	</Select>
	</smartFilterBar:customControl>
</smartFilterBar:ControlConfiguration>

Here is the code I am using in the controller:

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");
}

I used this code on a standard table and search field, but I am getting an error in the console stating 'getBinding' is not a function. I assume this is because that function does not exist in the smarttable controller.

Can anyone assist with what to do next?

Cheers,

Tim

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Tim,

oTable.getBinding() function doesn't exist for smart table. You can use oTable.rebindTable() and write your filtering logic code in onBeforeRebindTable() function as displayed in the following lines:

<smartFilterBar:ControlConfiguration groupId="_BASIC" key="ZQ_STAT" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="false">
    <smartFilterBar:customControl>
        <Select id="qualStatusDropDown" change="onQualSearch">
            <items>
		<core:Item key="0" text="0" />
		<core:Item key="1" text="ONE" />
		<core:Item key="2" text="TWO" />
		<core:Item key="3" text="THREE" />
             </items>
        </Select>
    </smartFilterBar:customControl> 
</smartFilterBar:ControlConfiguration>

and in your controller file:

onQualSearch : function (oEvent) {
this.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.rebindTable();                         // Call rebindtable function here
},

onBeforeRebindTable: function(oEvent) {                            //Add this function to your controller
this.mBindingParams = oEvent.getParameter("bindingParams");
this.mBindingParams.filters = this.oTableSearchState;
}                                                                                

Hope this helps 🙂

Former Member
0 Kudos

Thanks a lot for following up. I did end up figuring this out using the 'onBeforeRebindTable' function. Your method looks a little cleaner, though, so thanks again!

Answers (0)