Jemt / Fit.UI

Fit.UI is a JavaScript based UI framework built on Object Oriented principles
http://fitui.org
GNU Lesser General Public License v3.0
19 stars 7 forks source link

DropDown: Switching to TreeView is extremely slow when DropDown contains huge selection (15.000+) #167

Open FlowIT-JIT opened 1 year ago

FlowIT-JIT commented 1 year ago

See the following example: https://jsfiddle.net/475aobj9/2/

Fit.Events.OnReady(function()
{
    var dd = new Fit.Controls.WSDropDown("WSDropDown1");
    dd.Url("https://codemagic.dk/FlowIT/jsfiddle-dfva8mxh/data6.json");
    dd.GetTreeView().OnPopulated(function(sender)
    {
        dd.GetTreeView().SelectAll(true);
    });
    dd.MultiSelectionMode(true);
    dd.Width(400);
    dd.DropDownMaxHeight(150);
    dd.TextSelectionMode(true);
    dd.UseActionMenu(true);
    dd.InputEnabled(true);
    dd.Render(document.querySelector("#DropDownContainer"));

    window.dd = dd;
});

Example data can be found in data6.json.zip - make sure to update the URL on line 4: dd.Url("data6.json");

When working with huge amounts of selected items in a DropDown control, switching to the TreeView picker is painfully slow, which the example demonstrates.

Open the DropDown control and choose "Show available options". 16.000+ TreeView nodes will be loaded and selected. Now close the DropDown control, open it again, and click "Show available options" again - notice how long it takes for the TreeView to emerge.

This is due to the fact that selections in the DropDown control is synchronized to the picker control when it is made the active picker, in case the picker was not initially assigned to the DropDown control prior to assigning a value to the DropDown control:

https://github.com/Jemt/Fit.UI/blob/28ae44dfd5afcbbdec2fe29cd37a69df4512431d/Controls/DropDown/DropDown.js#L769

image

Most often we only need to do this the very first time a picker control is assigned to the DropDown control - and remember that any number of pickers might be used with the DropDown control, so we would need a flag for each individual picker control assigned!

Do make sure that changing selected state on picker controls directly does not cause new problems, if synchronization is only done once going forward. What happens if we call Clear() directly on the picker? Ideally it synchronizes the change back to the DropDown (expected), but it can not be allowed to cause inconsistency between the DropDown's selection and the picker's selection. Also try invoking dropdown.GetTreeView().Reload(false) and dropdown.GetTreeView().Reload(true) on an instance of WSDropDown. The first will not restore selected nodes, so this should result in DropDown's selection being cleared, while the latter keeps selection, meaning this should not affect the DropDown control's selection.

Marked as minor bug since huge selections like this is very rare.

FlowIT-JIT commented 1 year ago

Severity: With 1.500 selected nodes (test data: data2.json.zip) the problem is barely noticeable. Testet on a MacBook Pro 2017 with a 2.8 Ghz Core i7 CPU in Chrome v. 103. Throttling the browser by 6x using Developer Tools makes it less responsive but it is absolutely still usable. Selecting 1500 items in a DropDown control is also considered an unlikely use case. I'm removing the "minor bug" label.