How to use $select for odata call from ui5 app? - odata

I have an analytical view with the following columns -
sid, name, age, gender, and marks.
I cannot use select * because the gender column creates an error in viewing the output.
Hence I have to select all the columns except gender to view the result.
I have an OData service that queries the view.
The OData service is as follows -
service {
"_SYS_BIC"."test_package/AN_STUDENTS" as "query"
keys ("sid","name","age")
aggregates always (SUM of "marks");
}
settings {
support null;
}
I can view the OData result only when I use $select.
http://testservice.xsodata/query?$select=sid,name,age
Can anyone please advise how to bind a sap.m table to this OData service with its item aggregation such that the $select part is implemented in the OData call itself directly?

Use parameters option with select key to specify properties to retrieve.
<List items="{path:'query', parameters: {select: 'sid,name,age'}}">
</List>

Related

Get BreezeJS ODATA query parameters on server side to update entity during query

How do I get handle of the OData query parameters in a Brezze WebApi controller?
I have a endpoint where only a single entity will be queried at a time. The controller just calls a repository that returns a context.Set().AsQueryable();
I want to be able to get the entity ID out of the parameters and update(plain EF) a count property on it before querying it for the response.
Thanks
I found what I needed.
By adding a ODataQueryOptions<T> odataQueryOptions argument to the endpoint I was able to access the OData query parameters and get the ID I needed by getting this property:
var where = odataQueryOptions.RawValues.Filter;
Filter value in my case looks like this: Id eq 'dd3d6cb2-bc7a-467e-9730-c43c333b6fda'
Edit:
If you use .withParameters() on your breeze query object, you can pass additional parameters to your end-point without bothering to deal with OData.

SAPUI5 bind only one entity to list

I'm working on a SAPUI5 Project in SAP Web IDE. The idea is to consume data from a table in Backend System. The table is full of customers with different information to them. To achieve it I already created an oData service in the Backend System. The EntitySet provides all customers with all the concerning data. Calling just one Entity with the SAP Gateway client provides the same Information for just one customer. Now in the frontend, for the Fiori app, I already binded the oData Service to the project and achieved to set it as an template for an list and to display all customers in that list.
But what I want is to have an toolbar with an search field, so the user can search for a customer ID and then display just that one searched customer concerning to the number in my list as a list item. So i don't want to have the whole entity set to bind that list, just the one the user searched for.
So I think I have an function that is called when the user presses the search button and in that function I want to call the oData service Entity with the given ID in the search field. But I still don't get how to call the service and then bind it to the list item.
I searched a lot in the internet and books but what I found is too old or not working or not exactly what I need.
Can anybody please help me with the call and the binding to the list item ?
Here is how to implement filters in SAPUI5.
Consider you have a List with a search field in your view as:
<mvc:View
controllerName="namespace.MainController"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<List
id="invoiceList"
class="sapUiResponsiveMargin"
width="auto"
items="{/Invoices}" >
<headerToolbar>
<Toolbar>
<SearchField width="50%" search="onFilterInvoices"/>
</Toolbar>
</headerToolbar>
<items>
<ObjectListItem>
<!-- some items here -->
</ObjectListItem>
</items>
</List>
</mvc:View>
In the corresponding controller, you can do the following on Event triggered for the filter as:
onFilterInvoices : function (oEvent) {
// build filter array
var aFilter = [];
var sQuery = oEvent.getParameter("query");
if (sQuery) {
aFilter.push(new Filter("ProductName", FilterOperator.Contains, sQuery));
}
// filter binding
var oList = this.byId("invoiceList");
var oBinding = oList.getBinding("items");
oBinding.filter(aFilter);
}
More information of Filter:
sap.ui.model.Filter
Filter Operators
Filter working example
Kindly let me know if this helps!

SAPUI5 OData model with different metadata URI

I am using an OData model for a table, but the data is not loaded. The OData model is created by constructor in the following way:
new sap.ui.model.odata.ODataModel("/XMII/IlluminatorOData/QueryTemplate?QueryTemplate=testTemplate", {annotationURI: "/XMII/IlluminatorOData/$metadata"});
I cannot use the root URI of the OData service, because I need to specify a QueryTemplate.
After setting the model to the table, bindRows method is invoked with parameter "/Row".
table.bindRows("/Row")
The template for a column is a TextField.
template: new sap.ui.commons.TextField().bindProperty("value", "PROJECT")
The data is not shown and not even requested. Only metadata is fetched. What am I doing wrong with OData model? If I fetch the URI which was passed to the model with a get request, content is available.
Are you sure the URL is right?
Shouldn't it be something like "/XMII/IlluminatorOData/?QueryTemplate=testTemplate"
The ODataModel needs to load the metadata in order to work, this means it fetches it from "[ServiceUrl]$metadata", which would be "/XMII/IlluminatorOData/QueryTemplate/$metadata" in your case. But you also use the metadata as annotation source - there you use a different URL, so I guess you first one is wrong...?

AutoCompleteExtender ajax in asp.net ,

Hi I am using the AutoCompleteExtender ajax control. I am getting the list of strings in LIST collection. I want to populate only those strings, which user typing as prefix text. how to do this. I am following the example given in ajax toolkit.let say user typing "ca" then if list contain the list like,
'cat', 'dog', donkey', 'mouse','cart'....etc.
Then it should populate only 'cat' and cart'.
How to achieve this?
In the example there's a description of the properties. Quote:
ServiceMethod - The web service method to be called. The signature of
this method must match the following:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText, int count) { ... }
Note that you can replace
"GetCompletionList" with a name of
your choice, but the return type and
parameter name and type must exactly
match, including case.
ServicePath - The path to the web service that the extender will
pull the word\sentence completions
from. If this is not provided, the
service method should be a page
method.
So you need write a web service which will contain a method returning the list of suggestions based on the user input.

Implementing refined search - ASP.NET MVC

In my ASP.NET MVC application I have a view that displays a list of Products in the system. I would like to implement an option for users to filter the list of Products by selecting parametes, similar to the way it's done on www.codeplex.com. I would like to know how you would go about doing this in the most efficient and simple way? Any links to tutorials or guides are appreciated.
In our application we load up a list of all of the products into the web page, and use the Quicksearch jQuery plugin to filter the list. This allows the user to enter a word or two into a textbox, which collapses the list to only those entries matching what the user typed.
Basically, for a search of this type (server-side), you need:
Fields in a <form> for the user to fill out to perform the search request.
A button to post the form fields to your controller method
A repository for the Linq queries that will return the proper records.
A Method in the repository that accepts the parameters you have captured, and executes a linq query returning your filtered result, using Where clauses to filter the returned records.
The result of the query gets returned to the view for display.
If you need dynamic capabilities (i.e. the user may omit one or more parameters, and you need the flexibility to specify those parameters in the Linq query at runtime), then have a look at Dynamic Linq.

Resources