on 08-15-2016 4:00 PM
Hi guys,
I have an app with an XML view and controller.
What I need to do basically is to put a table on the view, and items with binding - however the binding filter should be dynamic.
So right now I'm having a workaround, which I have a feeling is not so great.
Is there a better way to do this than what I did?
In the controller, I can't get the table's binding, but only the binding info which I think is not recommended to use.
What I also want to avoid is to first load the data without the filter, and then put the filter.
This is what the XML view looks like:
...
<Table
id="table"
items="{
path: '/Rules',
filters: [],
sorter: {
path: 'Name',
descending: false
}
}"
growing="true"
growingScrollToLoad="true"
updateFinished="onUpdateFinished">
...
and the controller:
...
onInit : function () {
oTable = this.byId("table");
var appId = "Something not static";
var oBinding = oTable.getBindingInfo("items");
oBinding.filters = [new sap.ui.model.Filter("ApplicationId", "EQ", appId)];
...
Thanks,
Or.
Or
you can declare the end point in the table (view) then on the controller event ... onBeforeRendering you can apply the filter you need (dynamically)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can do this, SAPUI5 Explored
there dynamic filter used, check the handleConfirm function in Controller file, Dialog.fragment.xml is for the filter,sorter Pop-up(do check this too)
One more thing, "In the controller, I can't get the table's binding" Why?
if you are able to get the table control, I think you should get its binding too.
Thanks,
Chandan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chandan,
The thing is that I don't have the table bound to the model (oDataModel) yet, when I want to put the filter.
As you can see I declare the table in the XML view, and in the controller's onInit event I try to add the filter. At that point the table.getBinding() returns undefined, but the table.getBindingInfo() returns the binding info as I declared in the XML view.
In the example you sent, the table is already bound to the model, and then the filter is changed.
What I also want to avoid in my code is to bind the table to the path with all the items, and then put the filter, because then I have two calls to the bh. (I use oDataModel)
Thanks,
Or.
So a filter is predefined and on that data you want dynamic filter?
So if the Model is Odata, at onInit() read the model with your filter, then use the dynamic filter in a different function(as in my 1st reply).
Like this- inside onInit() do something like this-
oModel.read("/your_dataset",
null,
["$filter=your_entity eq 'value'"], // filter it
false,
function(oData, oResponse){
//oData will contain filtered data, bind it with the table
}
);
Now make use of SAPUI5 explored example filter in your own function.
This should do your job.
Thanks,
chandan
Why don't you move the items declaration from the view to the controller?
Regards,
Jamie
SAP - Technology RIG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because when I declare the items in the controller (with bindAggregation), I also need to move the table template there as well - otherwise there is an error thrown.
And since the template is the biggest part of the table definition - it turns out that I declare some controls in the XML view and some in the controller..
I want to keep the controls I declare in the controller at minimum.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.