Combobox in a DataItemTemplate - combobox

In the AspxGridView there are two comboboxes in DataItemTemplate, manually loaded. So when user selects one field of the first combo second will be disabled, i wrote this:
<dxe:ASPxComboBox ID="cmbEqualNotEqual" runat="server"
ClientInstanceName="cmbCEqualNotEqual" EnableClientSideAPI="true">
<Items>
<dxe:ListEditItem Text=" " Value="0" />
<dxe:ListEditItem Text="Eşittir" Value="1" />
<dxe:ListEditItem Text="Eşit Değildir" Value="0" />
</Items>
<ClientSideEvents SelectedIndexChanged="function(s,e){
alert(s.GetEnabled());
var selectedIndex = s.GetSelectedIndex();
if(selectedIndex == 2)
{
cmbCBiggerSmaller.SetEnabled(false);
}
}" />
</dxe:ASPxComboBox>
But this code disables the combo at the last row, not the row user works on. How can i disable the row user works on?
Thanks

I answer it for myself:
for (int i = 0; i < grid.VisibleRowCount; i++)
{
ASPxComboBox combito = grid.FindRowCellTemplateControl(i, grid.Columns[2] as GridViewDataColumn, "combito") as ASPxComboBox;
//combito.Value
}

The problem appears because the ClientInstanceName property is set for all editors in the same column to the same value. A possible solution is to handle the HtmlRowCreated event of the ASPxGridView and set the ClientInstanceName for both editors to a unique value. Also, in this event handler you should write the client side SelectedIndexChanged event handler. Finally, to obtain an editor instance, use the ASPxGridView's FindRowCellTemplateControl method.
Also, the following article can be helpful to you:
http://www.devexpress.com/Support/Center/ViewKBIssue.aspx?kbid=K18282

Related

Need to get dynamic count of the selected check-boxes

I'm having the two types of check-boxes one is for selectAll check-box in the data table header, and another type selecting the check-box for each row.
I'm doing a operation, So I need to show the confirmation message, How do I get the count of the selected check-boxes from the Managed Bean.
My code was written in JSF 1.2.
I can able to do select all records, select records, ManagedBean is working fine, But I need to get how many of them got selected for deletion.
Here is the JSF code,
<i:commandLink id="delete"
onclick="if (!confirm('#{managedBean.deleteSelectedCount}')) return false;"
action="#{managedBean.deleteRecords}"
title="Delete records"
immediate="true">
<i:graphicImage url="images/icons/delete.gif" alt="Delete records" />
</i:commandLink>
;
;//Some coding
;
//Data table code starts
<i:dataTable id="caseDataTable"
<h:column>
<f:facet name="header">
<i:selectBooleanCheckbox id="selectAllRecords" title="select All records"
value="#{managedBean.selectAll}">
<a4j:support event="onclick" reRender="caseDataTable,globalMessages" action="#{managedBean.actionSelectAllRecordss}" onsubmit="showBusyIndicator();" oncomplete="hideBusyIndicator();" />
</i:selectBooleanCheckbox>
</f:facet>
<h:outputLabel for="selectCheckbox" value="selectCheckbox"/>
<i:selectBooleanCheckbox id="selectCheckbox"
title="select a record" value="#{managedBean.selected}" >
<a4j:support event="onclick" reRender="selectAllRecords, globalMessages" action="#{managedBean.actionSelectionChange}"
onsubmit="showBusyIndicator();" oncomplete="hideBusyIndicator();"/>
</i:selectBooleanCheckbox>
</h:column>
Possible solution is to use h:inputHidden component (I think it exists in JSF 1.2. If not, you can find some alternative).
For example
Add h:inputHidden to the page
<h:inputHidden id="selectedCountHidden" value="#{managedBean.deleteSelectedCount}"/>
Each time you click on header check box or any of row check boxes, calculate deleteSelectedCount value and re-render h:inputHidden. Something like
<i:selectBooleanCheckbox id="selectCheckbox" title="select a record" value="#{managedBean.selected}" >
<a4j:support event="onclick" reRender="...,selectedCountHidden,..."
And now, since h:inputHidden will always hold deleteSeletedCount value, you can read its value via java script so there is no need for re-loading the page when you click on commandLink
<i:commandLink id="delete"
onclick="if(!confirm(document.getElementById('form:selectedCountHidden').value))return false;"..../>
Note that if you have form with id defined, you will need to call
document.getElementById('form:selectedCountHidden').value
Otherwise just call
document.getElementById('selectedCountHidden').value
In any case, inspect page source and you will find the exact id of p:inputHidden.

XPages comboBox values issue on partial refresh

I have 2 combo boxes and 1 input text field. On change of the 1st combo I set some value in the input field and partial refresh the panel where the input field is.
OnComplete of this refresh, i partial refresh (using XSP partialRefreshPost) the panel of the 2nd combo box. This combo box value as you can see is just the 1st combo's value.
The problem is:
The combo value is set but the input value is not! Although input's panel refresh comes first and on complete comes the combo's panel refresh. If i remove the code from inside the 2nd combo's value tab then the input field works. (or if i just remove the reference of the 1st combobox from the 2nd combobox then it works again).
The weird thing is:
if i use a listbox instead of the second combo box then it works!!
The xpage design is:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:table>
<xp:tr>
<xp:td>
<xp:comboBox id="comboBox1">
<xp:selectItem itemLabel="a" itemValue="a"></xp:selectItem>
<xp:selectItem itemLabel="b" itemValue="b"></xp:selectItem>
<xp:selectItem itemLabel="c" itemValue="c"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="panel1">
<xp:this.action><![CDATA[#{javascript:var inputText1:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText1");
inputText1.setValue("aaaaaa");}]]></xp:this.action>
<xp:this.onComplete><![CDATA[alert("refreshed panel1");
XSP.partialRefreshPost("#{id:panel0}",{onComplete: function(){alert("refreshed panel0");}});]]></xp:this.onComplete>
</xp:eventHandler></xp:comboBox></xp:td>
<xp:td></xp:td>
</xp:tr>
<xp:tr>
<xp:td></xp:td>
<xp:td></xp:td>
</xp:tr>
</xp:table>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:panel id="panel0">
<xp:comboBox id="comboBox2">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox1");
if(comboBox1.getValue()!=null){
return comboBox1.getValue().toString();
}else{
return "its empty";
}}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox></xp:panel>
<xp:br></xp:br>
<xp:panel id="panel1">
<xp:inputText id="inputText1"></xp:inputText>
</xp:panel>
<xp:br></xp:br>
<xp:br></xp:br></xp:view>
Just replace 2nd combo with this and see....
<xp:listBox id="listBox1">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox1");
if(comboBox1.getValue()!=null){
return comboBox1.getValue().toString();
}else{
return "its empty";
}}]]></xp:this.value>
</xp:selectItems>
</xp:listBox>
Any ideas?
When using a combobox, the first value in the list is the selected value. When you are using a list box, you have to choose a value from the list first. If you select a value, your example will fail too.
Because you are changing the allowed values of the combobox/listbox programmatically, and then try to set a value which is not longer in the list (the value is posted back to the server when doing a partial refresh), a validation error occurs, and the value of the inputText ('aaaaa') is not set in the backend.
You can add a xp:messages component inside of the panels, then you can see the error message.
Try doing this bind the controls to a viewScope then it should work.
I always bind my components to something scope variable, field or bean because if you don't you can get lot's of strange value problems. That's my experience.
I've tested you code and my suggestion works as far as I can see.

ZK ComboBox onchange changes all comboboxes in the listbox

I have an issue with a listbox and the combobox behaviour. I have a listbox with a group of rows and I try to edit inline and change the value of a field based on the values of a combobox. But when I select one value in the combo of one row then all the values of the comboboxes of the other rows change to the same value. Please, let me know what I am doing wrong. Thanks for your help!
Here is my code:
<template name="model" var="item">
<listitem >
<listcell label="#load(item.id)"/>
<listcell label="#load(item.descCodigoTrafico)"/>
<listcell label="#load(item.descAmbitoDeTrafico)"/>
<listcell>
<combobox
model="#load(vm.listaPrecioEspecial)"
onChange="#command('addToUpdate', entry=item)"
selectedItem="#load(item.precioEspecial) #save(item.precioEspecial, before='updateItems')">
<template name="model" var="el">
<comboitem label="#load(el)"/>
</template>
</combobox>
</listcell>
<listcell label="#load(item.tipoDescuento)" />
<listcell>
<decimalbox inplace="true"
value="#load(item.ppm) #save(item.ppm, before='updateItems')"
onChange="#command('addToUpdate', entry=item)"
format="#.0000"/>
</listcell>
</listitem>
</template>
And the code of the two methods in de VM:
#Command
public void addToUpdate(#BindingParam("entry") TblEscenarioCondTrafico item){
itemsToUpdate.add(item);
LOGGER.info(item.toString());
for(TblEscenarioCondTrafico i : itemsToUpdate){
LOGGER.info("Item a guardar " + i.toString());
//LOGGER.info("Elemento...");
}
}
#NotifyChange("listaTraficos")
#Command
public void updateItems() throws Exception{
EscenarioCondTraficoService ects = new EscenarioCondTraficoService(em);
for (TblEscenarioCondTrafico i : itemsToUpdate){
LOGGER.info("Guardando " + i.toString());
ects.save(i);
}
itemsToUpdate.clear();
listaTraficos = getListaTraficos();
}
The problem should be that
model="#load(vm.listaPrecioEspecial)"
sets the same Collection to every Combobox as its model and so it is bound to all Combobox instances.
I had the same problem, like Nabil A. said the problem was the model, the same for all the items. I solved creating a new model for every item.
Instead of:
model="#load(vm.listaPrecioEspecial)"
I put something like:
model="#load(vm.getNewListaPrecioEspecial())
And in the VM class you have to create a method named getNewListaPrecioEspecial that returns a new list. (In my case a new SortingPagingListModel)

Telerik MVC ComboBox in Grid not posting the right value

I have set up a ComboBox in grid. It shows everything fine but when I select anything in the ComboBox it is not posting the right value to the server, I debugged it and found out that it always posts value 0.
Any idea why is that and how to fix it?
Here's the important code:
**Controller**
//lista za stvaratelje (ComboBox)
var stvaratelji = newStvarateljiService.GetAllStvaratelje();
//za combobox
ViewBag.stvaratelji = stvaratelji;
//za selectlist
var listaStvaratelja = new SelectList(stvaratelji, "IdStvaratelj", "Naziv");
ViewData["stvaratelji"] = listaStvaratelja;
**View**
columns.ForeignKey(b => b.StvarateljId, (SelectList)ViewData["stvaratelji"]).Title("Stvaratelji").EditorTemplateName("Stvaratelji").Width("30%");
**EditorTemplate**
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.Telerik().ComboBoxFor(m => m)
.Name("Stvaratelji")
.Filterable(filtering =>
filtering.FilterMode(AutoCompleteFilterMode.Contains)
)
.Encode(false)
.AutoFill(true)
.BindTo((SelectList)ViewData["stvaratelji"])
%>
I am using selectList with foreignKey because when the grid is not in edit mode it shows value (ID) instead of the name, but that's a completely different issue and one not so important. Nevertheless if someone knows how to set ComboBox to show the name when the grid is not in edit mode it would be also appreciated.
I figured out what is the problem.
I changed the name of EditorTemplate's ComboBoxFor in "StvarateljId" because ComboBoxFor is not bound to the Title in the Grid but the name of the property in "ForeignKey" part.
Dario,
To address the question in the comment of your answer ("not to use SelectList"):
Have you tried changing from a ForeignKey to a simple Bound column with a DisplayTemplates/StvarateljId similar to the EditorTemplates? I have had some success with this setup instead of using the ForeignKey.
Here is a link to the demos at Telerik showing this exact setup.

Create an array from input field values with Flex 4.5

I have not been able to find any documentation and searches return useless docs not involving what I want to do.
I want to take the text entered by the user, and when they click Add Record it adds the text to the array. The list box at the bottom displays each item in the array in the order it was entered.
I am just a beginner with a basic understanding of how the code is written, but I have no idea which things to use in order to take the text, make it into a string, add it to the array, and display the array in the list.
The trick here is to just use the buttons click event to add an item to the ArrayCollection you use to provide the data to your list. Here's the sample I just came up with which does what I think you are asking:
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="HomeView">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var _records:ArrayCollection = new ArrayCollection();
protected function addRecord(event:MouseEvent):void
{
if(textInput.text != "") {
_records.addItem(textInput.text);
}
}
]]>
</fx:Script>
<s:TextInput id="textInput" left="10" right="10" top="5" prompt="Enter Text" />
<s:Button top="64" label="Add Record" horizontalCenter="0" click="addRecord(event)" />
<s:List left="10" right="10" top="132" bottom="5" dataProvider="{_records}" />
</s:View>

Resources