[CLOSED] MultiCombobox - Not able to get whether item is checked or unchecked

  1. #1

    [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:

    
          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]
  2. #2
    Hi @PriceRightHTML5team,

    I would implement it like that.

    Example
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>  
        
        <script>
            var onSelect = function(multiCombo, records) {
                var value = records[records.length - 1].data[multiCombo.valueField];
    
                multiCombo.suspendEvent("select");
    
                if ((value === "0") && multiCombo.getSelectedRecords().length > 1) {
                    multiCombo.clearValue(); // clears all
                    multiCombo.selectItem(0); // reselect the first item
                } else {
                    multiCombo.deselectItem(0);
                }
    
                multiCombo.resumeEvent("select");
            };
        </script>
    </head>
    <body>
        @X.ResourceManager()
        
        @(X.MultiCombo()
            .ID("MultiCombo1")
            .Items(
                new ListItem("All selected", "0"),
                new ListItem("Item 1", "1"),
                new ListItem("Item 2", "2"),
                new ListItem("Item 3", "3")
            )
            .Listeners(events => events.Select.Fn = "onSelect")
        )
    </body>
    </html>

Similar Threads

  1. Replies: 1
    Last Post: Apr 12, 2013, 12:22 PM
  2. A checked/unchecked TreeNode Sample
    By msnqu in forum Examples and Extras
    Replies: 6
    Last Post: Aug 09, 2012, 11:23 AM
  3. Checked/unchecked all subnode of a TreePanel
    By xeneus in forum 2.x Help
    Replies: 0
    Last Post: Jun 04, 2012, 1:13 PM
  4. Replies: 2
    Last Post: Nov 25, 2011, 4:47 PM
  5. Rise an event when checkbox is checked and unchecked
    By vishnukamatam in forum 1.x Help
    Replies: 4
    Last Post: Feb 04, 2010, 2:30 PM

Posting Permissions