Aug 20, 2014, 2:39 PM
[CLOSED] MultiCombobox - Not able to get whether item is checked or unchecked
Hi,
I have a simple MultiCombo box, which is used to display country list, i have a requirement where if user selects "First item" of combo box, rest items should get deselected and if any of the item is selected "First item" should get deselected.
For Example: Consider First item of MultiCombo box is "All Combined" and rest items is "Country1, Country2".
If "All Combined" is selected "Country1, Country2", should get deselected and vice versa.
I used Select event of MultiCombo but unable to get whether First items is checked or unchecked.
So how can we get whether current Item is checked or unchecked on Select event as it fire on both when item is selected & deselected?
Here is my code:
Controller & Model:
I have a simple MultiCombo box, which is used to display country list, i have a requirement where if user selects "First item" of combo box, rest items should get deselected and if any of the item is selected "First item" should get deselected.
For Example: Consider First item of MultiCombo box is "All Combined" and rest items is "Country1, Country2".
If "All Combined" is selected "Country1, Country2", should get deselected and vice versa.
I used Select event of MultiCombo but unable to get whether First items is checked or unchecked.
So how can we get whether current Item is checked or unchecked on Select event as it fire on both when item is selected & deselected?
Here is my code:
Controller & Model:
public class Country
{
public int COUNTRY_CD { get; set; }
public string COUNTRY_DESC { get; set; }
}
public ActionResult Index()
{
List<Country> list = new List<Country>();
Country obj = new Country();
obj.COUNTRY_CD = -2;
obj.COUNTRY_DESC = "All Combined";
list.Add(obj);
for (int i = 0; i <= 50; i++)
{
obj = new Country();
obj.COUNTRY_CD = i;
obj.COUNTRY_DESC = "Country-" + i;
list.Add(obj);
}
return View(list);
}
View :
@model List<TestProject.Controllers.MultiComboController.Country>
@using System.Web.Optimization;
@{
ViewBag.Title = "Home Page";
var X = Html.X();
}
@(Html.X().ResourceManager(ViewBag.ManagerConfig as MvcResourceManagerConfig))
<script>
var SelectCountry = function (record) {
if (record.data.COUNTRY_CD == -2) {
//if All Combined is checked all the rest countries should be deselected
//else if All Combined is unchecked only All Combined should be unchecked
}
else {
var item = App.CmbCountries.getStore().findRecord("COUNTRY_CD", -2)
App.CmbCountries.deselectItem(item);
}
};
//#region Function to make dropdown text as 'Multiselection' if more than one countries are selected
var myGetDisplayValue = function () {
var value;
if (this.valueModels.length > 1) {
value = "Multi-selection";
} else {
value = this.displayTpl.apply(this.displayTplData);
}
return this.wrapBySquareBrackets ? "[" + value + "]" : value;
};
</script>
<h2>Multi Select</h2>
@(
Html.X().Container().ID("cntr").Items(
X.MultiCombo().ID("CmbCountries")
.DisplayField("COUNTRY_DESC")
.ValueField("COUNTRY_CD")
.QueryMode(DataLoadMode.Local)
.Store(
X.Store().ID("storeCountries")
.Model(X.Model().Fields(
new ModelField("COUNTRY_DESC"),
new ModelField("COUNTRY_CD"))
)
.DataSource(Model)
)
.CustomConfig(x =>
{ x.Add(new ConfigItem() { Name = "getDisplayValue", Value = "myGetDisplayValue", Mode = ParameterMode.Raw }); })
.ListConfig(Html.X().BoundList().Listeners(events => events.Select.Handler = "SelectCountry(record)")) // Countries Combobox
.EmptyText("Select Countries").FieldLabel("Countries")
)
)
Thanks
Last edited by Daniil; Aug 26, 2014 at 6:43 AM.
Reason: [CLOSED]