on 10-28-2015 1:24 AM
tested on sapui5 version 1.28.6
In SmartFilterBar, if I define the a custom control, say checkbox. When press "search" button of filterbar. The filter value of the checkbox is not included as the filter of odata request. Thus the custom filter control has no use in query.
I think the problem maybe is that there's no documentation to describe, for a custom control, how to pass the value back to smartFilterBar to form a filter. Since custom control can be any type of control, there's no way for smartFilterBar to know how to get the value from the custom control and perform search with it.
If there's a way to do that, please advise.
Hello,
Let look at my example :
In your view :
In your code:
onBeforeRebindTable: function(oEvent) {
var mBindingParams = oEvent.getParameter("bindingParams");
var oSmtFilter = this.getView().byId("smartFilterBar");
var oSelect = oSmtFilter.getControlByKey("MyOwnFilterField");
var sVariant = oSelect.getSelectedKey();
var newFilter = new sap.ui.model.Filter("Variant", sap.ui.model.FilterOperator.EQ, sVariant );
mBindingParams.filters.push(newFilter);
},
In that way, the first query when you load your page will take in account your custom filters.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
i came up with a more convenient example that also takes existing filters into consideration:
beforeRebind: function(oEvent) {
var aFilters = oEvent.mParameters.bindingParams.filters,
aSorters = oEvent.mParameters.bindingParams.sorter,
sQuarter = this.getView().getModel("FilterModel").getProperty("/Quarter"),
oQuarterFilter;
if (sQuarter) {
oQuarterFilter = new sap.ui.model.Filter({
filters: [new sap.ui.model.Filter("ValidFr", "LE", sQuarter), new sap.ui.model.Filter("ValidTo", "GE", sQuarter)],
and: true
});
if (aFilters.length === 0) {
aFilters.push(oQuarterFilter);
} else if (aFilters.length === 1) {
if (aFilters[0].bAnd) {
aFilters[0].aFilters.push(oQuarterFilter);
} else {
var oTempFilter = new sap.ui.model.Filter({
filters: [aFilters[0], oQuarterFilter],
and: true
});
aFilters[0] = oTempFilter;
}
}
}
},
Hi Nils,
Thanks for responding. No error in the console is shown. The custom field does not load and the smart table is also not loaded. The Smart filter and smart table work fine when the custom control is not added.
Edit: I tried adding a normal sap.m.input field and it gets added. Just the Select control does not get added for some reason.
Regards,
Tejas
Message was edited by: Tejas S. Gargeya Sastry
Hi Nils,
Removing "customData:hasValue="true"" solved the issue. The select control now appears. Any thoughts as to why this might be happening?
Code:
<smartFilterBar:SmartFilterBar id="smartFilterBar" persistencyKey="myFilterKey" entityType = "ScenarioItem">
<smartFilterBar:controlConfiguration>
<smartFilterBar:ControlConfiguration groupId = "_BASIC" key="DateFrom" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="false"/>
<!--<smartFilterBar:defaultFilterValues>-->
<!-- <smartFilterBar:SelectOption low="2015-04-29T00:00:00" high="2015-05-19T00:00:00" operator="BT">-->
<!-- </smartFilterBar:SelectOption>-->
<!-- </smartFilterBar:defaultFilterValues>-->
<!--</smartFilterBar:ControlConfiguration>-->
<!--below field to upper case in backend-->
<smartFilterBar:ControlConfiguration groupId = "_BASIC" key="Groupname" visibleInAdvancedArea="true" hasValueHelpDialog = "false"/>
<!--below field to upper case in backend-->
<smartFilterBar:ControlConfiguration groupId = "_BASIC" key="ChangedName" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="false" hasValueHelpDialog = "false"/>
<smartFilterBar:ControlConfiguration groupId = "_BASIC" index = "1" key="cStatus" visibleInAdvancedArea="true"
label="Availablity" width = "300px" hasValueHelpDialog = "false">
<smartFilterBar:customControl>
<Select xmlns="sap.m">
<!--Keys to be changed as Y and N are used instead of X and nil in the DB-->
<core:Item key="A" text="All"/>
<core:Item key="X" text="Available"/>
<core:Item key="" text="Not Available"/>
</Select>
<!--<Input xmlns="sap.m"/>-->
</smartFilterBar:customControl>
</smartFilterBar:ControlConfiguration>
<smartFilterBar:ControlConfiguration key="cLockStatus" visibleInAdvancedArea="true"
preventInitialDataFetchInValueHelpDialog="false" label="Lock Status">
<smartFilterBar:customControl>
<Select xmlns="sap.m">
<core:Item key="A" text="All"/>
<core:Item key="X" text="Locked"/>
<core:Item key="" text="Unlocked"/>
</Select>
</smartFilterBar:customControl>
</smartFilterBar:ControlConfiguration>
<!--<smartFilterBar:ControlConfiguration id="idScn" key="ScnId" visibleInAdvancedArea="true" preventInitialDataFetchInValueHelpDialog="false" hasValueHelpDialog = "false">-->
<!--<smartFilterBar:defaultFilterValues>-->
<!-- <smartFilterBar:SelectOption id = "scnFilt" low="DRS01">-->
<!-- </smartFilterBar:SelectOption>-->
<!-- </smartFilterBar:defaultFilterValues>-->
<!--</smartFilterBar:ControlConfiguration>-->
</smartFilterBar:controlConfiguration>
<!-- layout data used to make the table growing but the filter bar fixed -->
<smartFilterBar:layoutData>
<FlexItemData shrinkFactor="0"/>
</smartFilterBar:layoutData>
</smartFilterBar:SmartFilterBar>
Message was edited by: Tejas S. Gargeya Sastry
The problem might be amissing namespace like xmlns:customData="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
Hello Aaron,
Did you find solution for custom smart control, for example checkbox ? I tried a lot of functions from tutorials but with no result. Still no query in $filter from custom controls, only OData requests work for me.
Thank you for reply.
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aaron,
I just discovered your question because I am working on the same topic. I think you have to include the value from the custom control manually.
I successfully added custom filter to the request in a method for the beforeRebindTable event of the SmartTable. If you have a look that the parameters that are in the event parameters of the method you can find a filter array. Add your filter to this array but be cautions with existing filters and handle them accordingly.
A little example:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.