How to take list item checkbox value in sap ui5 - sap-fiori

XML View
<List id="facebookList" items="{/}" mode="MultiSelect" selectionChange="onSelectionChange">
<StandardListItem type="Navigation" title="{account_name}" icon="{photo}" iconDensityAware="false" iconInset="false"/>
</List>
I have a list of items and checkboxes. When I click on checkbox, I want to take the value of checkbox in js controller. How to do this in sap fiori UI5

In the implementation of onSelectionChange method in the controller you can get the list item selected value as below,
onSelectionChange: function(oEvent) {
var selected = oEvent.getParameter("selected");
var selectedItem = oEvent.getParameter("listItem");
// ...
}
FYI, see this API selectionChange method

implement onSelectionChange method in your control
onSelectionChange:function(oEvent){
var selected = [];
var parameter = oEvent.getParameters();
if(parameter.listItem){
var item = parameter.listItem.getBindingContext().getObject();
if(item.selected){
selected.push(item);
}else{
selected.splice(selected.indexOf(item), 1);
}
}

onSelectionChange:function(oEvent){
console.log(oEvent.getParameters().selectedItem);
}
you will find the value in mProperties.

Related

Select interaction 'select' event

I have created a select interaction for my ol3 map and attached a select event handler.
selectInteraction = new ol.interaction.Select({
...
});
selectInteraction.on('select', function (evt) {
???;
});
How do I interrogate 'evt' to determine:
Which feature was clicked to fire the event?
The ID and other attributes of this feature?
Whether the feature was selected or deselected?
The select event emitted by the ol.SelectInteraction is documented here.
As you can see, evt.selected will be an array of all features that were just selected. It will not contain already selected features which are kept selected when clicking a new feature while the addCondition is true. These are the clicked features that were not already selected and matched the filters to be included in the selection.
Likewise, evt.deselected will contain any features that were just deselected.
You can get the ID and properties of each feature with:
var featureID = feature.getId()
var properties = feature.getProperties()
var someSpecificProperty = feature.get("property-name")
See the docs for ol.Feature for more info on the feature and it's attributes.
Here are some items that should help you.. evt.selected gets you the features that are selected. This example is on a clustered layer and you can use the get function on features selected to retrieve properties from the object selected. If you don't know properties available to you then use console.dir(evt) to examine the object using the console.
selectInteraction.on('select', function(evt){
var coord = evt.mapBrowserEvent.coordinate;
var selItems = evt.selected;
var sellength = selItems.length;
var rptFrame = parent.window.frames["rptframe"];
for (var i = 0; i < sellength; i++) {
var label = selItems[i].get('l');
var url = selItems[i].get('url');
if (url) {
rptFrame.location.href = url;
} else {
var feaObj = selItems[i].get('features');
if (feaObj.length == 1) {
url = feaObj[0].get('url');
rptFrame.location.href = url;
} else {
writeMultiSelect(rptFrame,selItems);
}
}
}
});

Using Dropdownlist selected value in IF statement MVC

I am new to MVC. I am trying for Cascading Dropdownlist in ASP.NET MVC 4. My problem is I want to access the selected countryid in #foreach loop
#Html.DropDownList("ddlCountry", new SelectList(#Model.Countries, "CountryId", "CountryName"))
$("#ddlCountry").change(function () {
#foreach (var item in #Model.States.Select(x=>x.countryId = ?))
{
}
});
How can I substitute countryId with the question mark above, so that I can filter the states
Thanks in Advance
Thanks
SRRIN
you can get the value in jquery by this
$("#ddlCountry option:selected").text();
As #Stephen said you cannot get the value of selected option using razor. Because the razor code is executed before page load.
A work around would be
$("#ddlCountry").change(function () {
var selectedVal= $("#ddlCountry option:selected").text();
var list = #Model.States.Tojson();
});
then use inArray for doing further operations
Thanks to all.
As Stephen and Nikitesh stated, javascript variable are not accessible inside razor scripts. So I succeeded with following approach.
var selectedCountryId = $("#ddlCountry").val();
var states = #Html.Raw(Json.Encode(Model.States));
for (var i = 0; i < states .length; i++) {
if (states [i].countryid == selectedCountryId ) {
... populate states here
}
}
Thanks
SRRIN
you can use dropdown selected value and pass in your query as:
#Html.DropDownList("ddlCountry", new SelectList(#Model.Countries,"CountryId", "CountryName"))
$("#ddlCountry").change(function () {
var countryId=parseInt($(this).val());
#foreach (var item in #Model.States.Select(x=>x.countryId = countryId))
{
}
});

Sitecore Accessing Field value to ASP Control

Can any one tell me if I can use a ASP Control instead of Field Renderer to display the field.Please see below illustration.
Note:I need to do it in the Item Databound Event of Repeater.
I have a template with Field as External Link .Eg :Contact US .One way to display that link in the page is using field renderer as below.
ContactUS.aspx:
<asp:Repeater ID="rptContactUS" runat="server" OnItemDataBound="Menu_OnItemDataBound">
<ItemTemplate>
<item><sc:FieldRenderer ID="frContactUS" runat="server"/></item>
</ItemTemplate>
</asp:Repeater>
ContactUS.aspx.cs:
protected void Menu_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
Field item = (Field)e.Item.DataItem;
if (item != null)
{
FieldRenderer frContactUS= (FieldRenderer)e.Item.FindControl("frContactUS");
if (frContactUS!= null)
{
frContactUS.FieldName = item.Name;
}
}
}
The above code works fine.My Question is Whether I can use a Asp control instead of FieldRenderer and assign the link value from the Field Item to asp href property of the link in item databound event of repeater.If yes,Please tell me how?
Thanks,
Suhas
Yes you can. From what I see in your example you are binding Field to the Menu.
You could also bind a List of Items to your menu. You can then retrieve the item's fields in the repeater like this:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Item dataItem = (Item)e.Item.DataItem;
System.Web.UI.WebControls.HyperLink hl = (System.Web.UI.WebControls.HyperLink)e.Item.FindControl("hl");
if (hl != null)
{
Sitecore.Data.Fields.LinkField url = dataItem.Fields["linkfield"];
if (url != null)
{
hlMerk.NavigateUrl = url.Url;
hlMerk.Target = url.Target;
// more properties are available check sitecore documentation
}
}
}
}
From here you will have the url field (obviously you should give the correct field name instead of url.
The LinkField has several properties as described in the general Sitecore documentation that can be found # http://sdn.sitecore.net.

ZK set selected item after AnnotateDataBinder loadAll()

I'm new to ZK. I have a Listbox with a List as model. When I receive an update event I update the information in the model and then I update the UI using
AnnotateDataBinder binder = (AnnotateDataBinder) vesselsList.getPage().getAttribute("binder");
if (binder != null) {
binder.loadAll();
}
The problem is that after the update, in the following code
List updatedObjects = object.getItems();
for (Object obj : updatedObjects) {
Listitem data = (Listitem) obj;
Object ob = data.getValue();
The data.getValue() is always null.
I have search the internet for many days and I found that the binder launches an onInitRenderLater event after load everything but I can't manage to make it work.
My intent is if I have an item selected before the update,I want it to remain selected and the binder.loadAll().
Did you setValue to your items with annotated databinding ?
<listitem value="#{bean.data}" > .... </listitem>
In zul I made
<listbox model="#{objects_model}" id="objectsList"
and in Java I call the method
public void onAfterRender$objectsList(Event event) {
// select item here after the listbox has been rendered
}
it did the trick

ASP .net MVC Jqgrid data binding

I am using a jqgrid with a column named 'Comments'. My controller code returns data as follows:
var jsonData = new
{
rows=
....
....
select new
{
col1....
col2....
Comments = _Model.GetComments(id),
})
.......
.....
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
_Model.GetComments(id) will return a ClientComments Object which has a few properties say CommentID, FirstName, MiddleName etc., which will be bound to each row in the grid
Now in my jqgrid I need to build a tool tip based on Comments column properties and for that I need to use the properties of my Comments in JQGrid for each row. May I know How I can manipulate Comment's properties for each row? Any help would be appreciated.
I tried in my javascript that for each row rowObject.Comments.FirstName and it did not work.
For the JavaScript version of the grid you would use getDataIDs to get the ID of each row, and then use getRowData to read the data at that row. For example:
var ids = $("#grid").getDataIDs();
for(var i=0; i<ids.length;i++){
var rowdata = $("#grid").getRowData(ids[i]);
// Build tooltip here using rowdata.FirstName, rowdata.MiddleName, etc.
}
But, are you working with the JavaScript version of jqGrid or jqGrid ASP.NET component?

Resources