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!
Related
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>
I'm making a game website and using GiantBombs.com API. I've finished a search function and on a search I get the results in a table.
I want every row to be a link to the "Game Profile" i want on the site.
My issue is I can't figure out how to give every game a unique URL, only using 1 View.
E.g:
Localhost/Gameprofile/XXX-XXX - where X is the "ID" property of the game on GiantBomb
For my search function I could use this which generate a URL based on the search.
<form method="get" action="/URL">
<input id="searchField" name="search">
<input type="hidden" id="myValue" value="#ViewBag.sq" />
However, I can't figure out how to do this on a Table.
If you have all of the information about each game stored in a database table then you can do something like this:
You need to pass the games ID as a parameter to the function that loads your page. For example:
//One Page
public ActionResult Gameprofile(int ID)
{
//Query your database, to return only the related rows.
//To do this you can refer to the parameter you just passed in.
return View();
}
You can call the function from your index page like so:
#Html.ActionLink("Gameprofile", "ControllerName", new { .ID = "myValue"});
I'm not entirely certain that this is what you're aiming for, but hopefully it helps.
If you're new to mvc, there's plenty of help and advice on stack overflow and the MSDN.
I have an MVC 5 / Bootstrap application. On one of the pages, I have a number of fields all bound to the model associated with the page. However, I also have a simple unordered list which always starts out empty and the user can then add items to it. They do this by entering some text into a type ahead field. Once the user finds what he/she is looking for, he/she can click a button and have it added to the unordered list. Any number of items can be added to the list. All of this works fine.
My question is how I can get the contents of the unordered list posted back to the server along with the rest of the form contents, since the unordered list isn't part of the model?
Here is one way to skin this cat:
A) Add a collection to your model (which really should be a ViewModel, and not a domain model) to hold those items
B) In your button's click handler, create a hidden input field that conforms to the ASP.Net Wire Format: http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx
If you had a collection of orders, you should end up generating controls like this:
<input type="hidden" name="Orders[0].Id" value="1" />
<input type="hidden" name="Orders[1].Id" value="2" />
Note sequential ordering is important, if you start removing items, you'll need to re-sequence your name values.
There couple of ways to work it out.
If you don't want to add to model, what I would prefer to do you can:
Directly access item that were posted via Controller.Request property;
You can post this items separately via Ajax request, and handle them in different controller action.
I need solution for my problem on urgent basis, I am new with mvc, knockout please provide me sample code for my problem. any help will be highly appreciated.
suppose I have an observable array in my viewmodel i.e
var viewmodel = {
vendorproviders : ko.observablearray([])
}
where vendorproviders list consist of multiple attributes like id, name, country, address etc
I want to populate that array in my grid where each row will have a select button, when that button is clicked it should post the id to my controller action either by submitting or by ajax call.
Furthor more that grid should be searchable like if there is a separate text box, based on the value of text box grid should display matching providers else display all providers.
when user search for particular provider grid should populate from observable array instead of making call at server again and again to pupulate the observable array.
I would suggest starting here.
http://learn.knockoutjs.com/#/?tutorial=intro
What you are talking about is all the basic functionality of the tools you referenced.
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.