Skip to Content
0

SmartTable Filter

Dec 15, 2016 at 11:02 PM

98

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
avatar image
Former Member
Jan 05, 2017 at 05:53 AM
0

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 :)

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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!

0