PDA

View Full Version : [CLOSED] [#551] Scroll to current Item in ComboBox trigger click



AaronDev
Sep 16, 2014, 7:19 PM
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.

Daniil
Sep 16, 2014, 7:49 PM
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>

AaronDev
Sep 16, 2014, 8:57 PM
Thanks that works perfectly.

Yea, thought the same, but glad it's possible!

geoffrey.mcgill
Sep 16, 2014, 9:22 PM
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.

Daniil
Sep 17, 2014, 5:24 AM
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.

geoffrey.mcgill
Sep 17, 2014, 6:07 AM
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:

http://forums.ext.net/attachment.php?attachmentid=15181&stc=1

The second image shows the proposed scroll position:

http://forums.ext.net/attachment.php?attachmentid=15191&stc=1

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.

Daniil
Sep 18, 2014, 8:35 AM
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.

Daniil
Sep 18, 2014, 1:30 PM
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.

AaronDev
Sep 18, 2014, 1:48 PM
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.

Daniil
Sep 18, 2014, 3:30 PM
Thank you for sharing your opinion. I tend to agree with you.

geoffrey.mcgill
Sep 18, 2014, 3:32 PM
Yes, agreed. Maintaining scroll position would be the best solution.

Daniil
Sep 19, 2014, 11:20 AM
Maintaining scroll position has been implemented in the SVN trunk, the revision #5986. It will go to the v2.5.3 release.