[CLOSED] setSelectedItems on ext:MultiSelect does not work

  1. #1

    [CLOSED] setSelectedItems on ext:MultiSelect does not work

    Hi Guys

    Trying to do select all in multiselect control , this worked in ext 2.5 but not working on ext 4.1 , on debugging further in console figured out Ext.Array.from does not assign index property to the array list, so none of select conditions to select item are true , Following is the code please check

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultiselectList.aspx.cs" Inherits="MultiselectList" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script>
    
            function selectAllItemsinSectionList() {
                app.sectionSelector.setSelectedItems(app.sectionSelectorStore.data.items);
    
            }
    
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
    
    
                <ext:ResourceManager ID="ResourceManager1" runat="server" CleanResourceUrl="true" DirectMethodNamespace="DM_MSelect" Namespace="app">
                </ext:ResourceManager>
    
    
                <ext:Panel ID="pnl1" runat="server" Width="400" Height="500">
                    <TopBar>
                        <ext:Toolbar runat="server">
                            <Items>
                                <ext:Button ID="btmSelectAll" Text="SelectAll Items" runat="server">
                                    <Listeners>
                                        <Click Fn="selectAllItemsinSectionList"></Click>
                                    </Listeners>
                                </ext:Button>
                            </Items>
                        </ext:Toolbar>
                    </TopBar>
                    <Items>
    
                        <ext:MultiSelect SingleSelect="false" ID="sectionSelector" DisplayField="sectionname" ValueField="sectioncode" runat="server" Border="false" AutoScroll="false">
                            <Store>
                                <ext:Store runat="server" ID="sectionSelectorStore">
                                    <Model>
                                        <ext:Model ID="Model5" runat="server" IDProperty="orderno">
                                            <Fields>
    
                                                <ext:ModelField Name="sectioncode"></ext:ModelField>
                                                <ext:ModelField Name="sectionname"></ext:ModelField>
    
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                        </ext:MultiSelect>
    
                    </Items>
    
                </ext:Panel>
    
    
            </div>
        </form>
    </body>
    </html>

    code below

    using Ext.Net;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class MultiselectList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
    
                this.sectionSelectorStore.Data = Data;
                this.sectionSelectorStore.DataBind();
    
            }
        }
    
    
        private List<sections> Data
        {
            get
            {
    
                List<sections> lstData = new List<sections>();
    
                lstData.Add(new sections { sectioncode = "01", sectionname = "Section 1" });
                lstData.Add(new sections { sectioncode = "02", sectionname = "Section 2" });
                lstData.Add(new sections { sectioncode = "03", sectionname = "Section 3" });
                lstData.Add(new sections { sectioncode = "04", sectionname = "Section 4" });
    
    
    
                return lstData;
            }
        }
    
    
        public class sections
        {
            
                                               
            public string sectioncode { get; set; }
            public string sectionname { get; set; }
        }
    
    }
  2. #2
    Hello @amitpareek!

    Forums search is your friend! :)

    Look at this thread: Set MultiSelect selected items during DirectEvent.

    The key word here is: updateSelectedItems().

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi,
    We were looking at the solution for client side and hence we did not find the direct event thread. I will try the solution.
    Is setSelectedItems deprecated?
  4. #4
    We are using this in MVC 5 , Can you please guide why setSelectedItems wont work ? need a javascript solution please . Looks like Ext.Array.from has a bug where it wont assign index property to the array

    Thanks
    Amit
  5. #5
    Hello @amitpareek!

    Sorry, misleading "lead" from me. In fact updateSelectedItems() in code behind but calls setSelectedItems(). But that's not meant to work in this situation.

    Have you taken a look in our examples on the MultiSelect tool? There's the Forms -> MultiSelect -> Item Selector that just shows how to select some items.

    Unfortunately, it is not so straightforward as to bind the records and it does select them, but selects by their index.

    Well, long story short, you can use this on your JavaScript to select all entries in the list:

    function selectAllItemsinSectionList() {
        var i,
            storeEntries = app.sectionSelectorStore.data.items,
            entries = [];
    
        for (i = 1; i <= storeEntries.length; i++) entries.push(i);
    
        app.sectionSelector.setValue(entries);
    }
    I hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] MultiSelect : Load multiselect with proxy not working
    By matrixwebtech in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Feb 20, 2015, 4:01 PM
  2. [CLOSED] Populate TagField From Multiselect and Remove Item from Multiselect
    By matrixwebtech in forum 2.x Legacy Premium Help
    Replies: 12
    Last Post: Oct 13, 2014, 2:44 PM
  3. Replies: 0
    Last Post: Oct 12, 2012, 10:45 AM
  4. Replies: 4
    Last Post: May 09, 2012, 9:24 PM
  5. Replies: 4
    Last Post: Feb 20, 2012, 11:14 AM

Tags for this Thread

Posting Permissions