[CLOSED] Itemselector questions

  1. #1

    [CLOSED] Itemselector questions

    Hi guys,

    Trying to use the itemselector, but I have 2 questions in my test app:

    Why do I need to update the selecteditems to show the (still non selected) items in the 'available' box initially ?

    Why can I loop throught the .selectedItems after choosing some --> Save, but can't I loop through the .items collection because it seems to be empty ?

    Where do I go wrong ? :)

    .aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="iWise3.Test.WebForm1" %>
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Test</title>
        <style>
            .label {
                font    : bold 11px tahoma,arial,sans-serif;
                width   : 300px;
                height  : 25px;
                padding : 5px 0;
                border  : 1px dotted #99bbe8;
                color   : #15428b;
                cursor  : default;
                margin  : 10px;
                background  : #dfe8f6;
                text-align  : center;
                margin-left : 0px;
            }
        </style>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:FormPanel
                runat="server"
                Title="ItemSelector Test"
                Width="700"
                BodyPadding="10"
                Height="450"
                Layout="fit"
                >
                <Items>
                    <ext:ItemSelector
                        ID="ItemSelector1"
                        runat="server"
                        FieldLabel="ItemSelector"
                        FromTitle="Available"
                        ToTitle="Selected">
                    </ext:ItemSelector>
                </Items>
                <DockedItems>
                    <ext:Toolbar runat="server" Dock="Bottom">
                        <Items>
                            <ext:Button runat="server" Text="Save" Handler="App.direct.SaveFilter()"/>
                        </Items>
                    </ext:Toolbar>
                </DockedItems>
            </ext:FormPanel>
        </form>
    </body>
    </html>
    .cs
    using System;
    using System.Diagnostics;
    using Ext.Net;
    using ListItem = Ext.Net.ListItem;
    
    
    namespace iWise3.Test
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        ListItem li = new ListItem
                        {
                            Value = i.ToString(),
                            Text = $"Item {i}"
                        };
                        ItemSelector1.Items.Add(li);
                    }
                    //ItemSelector1.Update();
                    ItemSelector1.UpdateSelectedItems(); // Why is it empty without ?
                }
            }
    
    
            [DirectMethod]
            public void SaveFilter()
            {
                foreach (ListItem li in ItemSelector1.Items)
                { 
                    Debug.WriteLine($"Item: {li.Value}"); // Empty ???
                }
                foreach (ListItem sli in ItemSelector1.SelectedItems)
                {
                    Debug.WriteLine($"Selected Item: {sli.Value}");
                }
            }
        }

    Martin
  2. #2
    Hello Martin!

    As for your first question, it looks like due do an error the itemSelector component does not load a store bound to it in build/render time and calling UpdateSelectedItems() (C#) or setSelectedItems([]) (JS) works that around. I couldn't find at a first glance why exactly it is not loading the items, so I don't have a better reply for you right away.

    As for the other question, the store items are not on code behind during postback cause a full store is not submit by default on every postback -- it could mean lots of data submit, so it has to be handled to the user whenever required.

    The selected items are sent on postback/submit as regular form fields' contents. In general, you have a form (a combo box for example), when you submit it, you submit the entries you selected there, you don't submit back the actual contents of the combo box, as the possible entries generally is a fixed amount of entries or determined by the server anyway, and not something the user interacted with.

    I hope this helps! Do you have a problem with UpdateSelectedItems() and need an alternative not to call it? Being too annoying to call it on your application and usage?

    There is an open issue to ItemSelector but it does not really look like the issue you are complaining about.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi Fabricio,

    Thank you for your long anwser. I can work around my second question, so that's no problem. The first question was just out of curiosity. I couldn't comprohend what I was doing :)

    Martin
  4. #4
    Hello again, Martin!

    This is maybe the first time this usage appeared in a forum thread: ItemSelector data binding. But it wasn't considered a problem by the time it happened.

    I hope this helps a little with knowing the background about this option. Anyway, the UpdateSelectedItems() just calls the JavaScript-sided setSelectedItems([]) with exactly this argument and in a few attempts I couldn't make the entries show up in your test case without this call.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] ItemSelector questions
    By cwolcott in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 22, 2016, 2:25 PM
  2. [CLOSED] The ItemSelector can not be empty
    By CarWise in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 01, 2015, 3:48 PM
  3. Replies: 2
    Last Post: May 05, 2015, 1:49 PM
  4. [CLOSED] [1.0] Couple MVC questions and property questions
    By alliedwallet.com in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 28, 2010, 11:01 AM
  5. How to load itemselector
    By amanind in forum 1.x Help
    Replies: 0
    Last Post: Jul 21, 2010, 11:18 AM

Posting Permissions