PDA

View Full Version : [CLOSED] Multi select in Multicombo in js



Tactem
Dec 12, 2012, 10:27 AM
Hi guys,

I have a multicombo same http://examples2.ext.net/#/Form/ComboBox/MultiCombo/ (simple multicombo) in my form.

in a gridpanel, i have a string containting string with textvalue of the multicombo.

When i select a row, i would like select all itemValue in multicombo present in my row.

Page.aspx

<ext:MultiCombo ID="Multi" runat="server" MultiSelect="true"
Cls="donneesAlert" ReadOnly="true">
</ext:MultiCombo>


Page.js


if (values[6] != '') {
var listeAddresse = values[6].split(',');
for (i = 0; i < Ext.getCmp('Multi').store.data.items.length; i++) {
for (j = 0; j < listeAddresse.length; j++) {
if (Ext.getCmp('Multi').store.data.items[i].data.field2 == listeAddresse[j] || ' '+Ext.getCmp('Multi').store.data.items[i].data.field2 == listeAddresse[j]) {
Ext.getCmp('Multi').select(Ext.getCmp('Multi').sto re.data.items[i]);
}
}
}
}

But i can't select only one item together.

How multi-select in js without all selected ?

Regards

Yoann

Daniil
Dec 12, 2012, 12:22 PM
Hi Yoann,

I might misunderstand something, but what about a setValue call?

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.MultiCombo1.GetStore();
store.DataSource = new object[]
{
new object[] { "1", "Item 1" },
new object[] { "2", "Item 2" },
new object[] { "3", "Item 3" }
};
store.DataBind();
}
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:MultiCombo
ID="MultiCombo1"
runat="server"
DisplayField="text"
ValueField="value">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
</ext:MultiCombo>
<ext:Button runat="server" Text="setValue" Handler="App.MultiCombo1.setValue(['1', '2']);" />
</form>
</body>
</html>

Tactem
Dec 12, 2012, 12:42 PM
Thank, i have tried ['Item 1', 'Item 2'] or ['1,2'] or '[1,2]' but ['1','2'] is ok.*

Function version


if (values != '') {
var listeAddresse = values.split(',');
var nbLigne = 0;
var tableau = new Array(); ;
for (i = 0; i < Ext.getCmp('Multi').store.data.items.length; i++) {
for (j = 0; j < listeAddresse.length; j++) {
if (Ext.getCmp('Multi').store.data.items[i].data.field2 == listeAddresse[j] || ' ' + Ext.getCmp('Multi').store.data.items[i].data.field2 == listeAddresse[j]) {
tableau[nbLigne] = Ext.getCmp('Multi').store.data.items[i].data.field1;
nbLigne = nbLigne + 1;
}
}
}
Ext.getCmp('Multi').setValue(tableau);
}
else Ext.getCmp('Multi').setValue('');