[CLOSED] [#551] Scroll to current Item in ComboBox trigger click

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] [#551] Scroll to current Item in ComboBox trigger click

    In a combobox setup with

    .TriggerAction(TriggerAction.All)
    so that all items display in the dropdown. Is it possible to scroll to the currently selected record when the dropdown is triggered.

    Something like the grids scrollintoView on the trigger click.
    Last edited by Daniil; Sep 18, 2014 at 8:36 AM. Reason: [CLOSED]
  2. #2
    Hi @AaronDev,

    Welcome to the Ext.NET forums!

    Honestly, I am a bit surprised why there is no such a setting to scroll to the selected item (also I would expect it to be true by default).

    As a solution, I can suggest to listen to the Expand event and scroll.

    Example
    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                object[] data = new object[50];
    
                for (int i = 0; i < 50; i++)
                {
                    data[i] = new object[] { i, "Item" + i };
                }
                
                this.ComboBox1.GetStore().DataSource = data;
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    
        <script>
            var onExpand = function() {
                var me = this,
                    picker = me.picker,
                    selected, itemNode;
    
                if (picker.getSelectionModel().hasSelection()) {
                    selected = picker.getSelectionModel().getSelection()[0];
                    itemNode = picker.getNode(selected);
    
                    if (itemNode) {
                        picker.listEl.scrollChildIntoView(itemNode, false);
                    }
                }
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:ComboBox 
                ID="ComboBox1" 
                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>
                <Listeners>
                    <Expand Fn="onExpand" />
                </Listeners>
            </ext:ComboBox>
        </form>
    </body>
    </html>
  3. #3
    Thanks that works perfectly.

    Yea, thought the same, but glad it's possible!
  4. #4
    This seems like a feature(?) we need to build into the ComboBox.

    I will discuss with @daniil and maybe we can implement this as the default functionality in the next release.
    Geoffrey McGill
    Founder
  5. #5
    I was also thinking about that. It should not be a problem to implement it.

    Geoffrey, do you think we should change the existing behavior? I mean should it scroll by default? We can make it configurable, at least. True or false by default? Please share your opinion.
  6. #6
    Here's a challenge... I think I'd prefer if the selected Item was scrolled to the middle of the visible list.

    The following two images demonstrate. The first shows the existing functionality, with the onExpand fix:



    The second image shows the proposed scroll position:



    If "scroll to the middle" requires too much bloat, then "scroll to the item" is good enough.

    I don't think there should be a config for this functionality, it should have been working this way to begin with. I'd consider the existing (non-scrolling) functionality to be a defect.

    Hope this helps.
    Attached Thumbnails Click image for larger version. 

Name:	Screenshot 2014-09-17 00.02.58.png 
Views:	40 
Size:	13.5 KB 
ID:	15181   Click image for larger version. 

Name:	Screenshot 2014-09-17 00.03.18.png 
Views:	39 
Size:	14.6 KB 
ID:	15191  
    Geoffrey McGill
    Founder
  7. #7
    Agree, it looks a defect. Also, center alignment appears to be best.

    Created an Issue:
    https://github.com/extnet/Ext.NET/issues/551

    It has been fixed (with center alignment) in the SVN trunk in the revision 5981. It will go to the v2.5.1 release.

    Thank you for bringing the problem to us.
  8. #8
    I've just tested with Ext.NET v3 (ExtJS 5). The scrollbar position is preserved (maybe, restored) on trigger clicks. Do we really need to change that behavior in Ext.NET v3? I think it might be expected by user. Though, it is a slight difference in the behavior between v2 and v3. Seems, no problem with that.

    Please share your opinion.
  9. #9
    Either would have suited my needs and maybe even the v3 behaviour would be preferable. Sometimes the users can use the dropdown as a reference without actually selecting an item and in that case it's better to stay were they were the last time they scrolled.
  10. #10
    Thank you for sharing your opinion. I tend to agree with you.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Combobox Click Trigger allways reload data
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 26, 2013, 5:01 PM
  2. Replies: 4
    Last Post: Jan 21, 2013, 7:09 AM
  3. [CLOSED] combobox column in grid and get selected item on row click
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 23, 2011, 2:38 PM
  4. [CLOSED] ComboBox trigger click fails to clear value
    By Ben in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 02, 2009, 9:51 AM
  5. Combobox trigger - click set empty text
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Aug 09, 2009, 3:48 PM

Posting Permissions