[FIXED] [#688] [3.1.0] MultiCombo SortByDisplayField / SortByValueField

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [FIXED] [#688] [3.1.0] MultiCombo SortByDisplayField / SortByValueField

    I noticed that neither SortByDisplayField nor SortByValueField were working on the MultiCombo.

    This override seems to fix it. I don't know if that's the best way to go about it or not.

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
    <title>MultiCombo SortByDisplayField</title>
    
    <script type="text/javascript">
    Ext.define('GL.overrides.net.MultiCombo', {
        override: 'Ext.net.MultiCombo',
    
        onBindStore: function (store, initial) {
            this.callParent(arguments);
            
            // add sorting to valueCollection
            if (store && (this.sortByDisplayField || this.sortByValueField)) {
                this.valueCollection.sort(this.sortByDisplayField ? this.displayField : this.valueField, 'ASC');
            }
        }
    });
    </script>
    </head>
    <body>
    <form runat="server">
    <ext:ResourceManager runat="server" />
    
    <ext:MultiCombo runat="server" ID="MultiCombo1" SortByDisplayField="true" Width="300">
        <Items>
            <ext:ListItem Text="Item E" Value="1" />
            <ext:ListItem Text="Item D" Value="5" />
            <ext:ListItem Text="Item C" Value="3" />
            <ext:ListItem Text="Item B" Value="4" />
            <ext:ListItem Text="Item A" Value="2" />
        </Items>
        <SelectedItems>
            <ext:ListItem Value="1" />
            <ext:ListItem Index="4" />
        </SelectedItems>
    </ext:MultiCombo>
    <br />
    <ext:FieldContainer runat="server" Layout="HBoxLayout" Width="300">
        <Items>
            <ext:TextField runat="server" ID="JsonText" FieldLabel="JSON Value" LabelWidth="80" Flex="1" />
            <ext:Button runat="server" Text="Get" Handler="function () { #{JsonText}.setValue(Ext.encode(#{MultiCombo1}.getValue())); }" />
            <ext:Button runat="server" Text="Set" Handler="function () { #{MultiCombo1}.setValue(Ext.decode(#{JsonText}.getValue() || '[]')); }" />
        </Items>
    </ext:FieldContainer>
    </form>
    </body>
    </html>
    Last edited by Daniil; Feb 09, 2015 at 11:46 AM. Reason: [FIXED] [#688] [3.1.0]
  2. #2
    Hello, Scott!

    For some reason, your approach did not work for me, neither on v3.0 nor v3.1 beta. But thanks for your advice, I could come up with a solution that might work for you as well. It is just a matter of changing your override to:

    Ext.define('GL.overrides.net.MultiCombo', {
        override: 'Ext.net.MultiCombo',
    
        onBindStore: function (store, initial) {
            this.callParent(arguments);
            
            // add sorting to valueCollection
            if (store && (this.sortByDisplayField || this.sortByValueField) && this.store.sorters.length == 0)
                this.store.sorters.add([{ property: this.sortByDisplayField ? "field2" : "field1", direction: "ASC" }]);
        }
    });
    Here, I just add a sorter to the store depending on the boolean you chose while defining the combo.

    In my tests here, the fields were named both field1 and field2 for value and display fields, respectively.

    But in the end, as your solution works for you, the other approach I provided to you is no better or worse. It just seemed to work in situations where your suggestion didn't.

    I'll take this to our development team so we can check and fix this on the running code. The origin of this option was on this thread from 2012: MultiCombo. As this was an feature specific to Ext.NET, when updating ExtJS that feature was probably overlooked.

    Thanks again for reporting!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Fabricio,

    It's not the sort on the picker that I was attempting to alter. It's the order of the comma-delimited values displayed in the field. Without the override, it will always list the values in the order clicked regardless of SortByDisplayField or SortByValueField. I validated against SVN trunk revision 6313.

    v2.5.3 also will display the items in the picker in the same order as they were in the markup, so I expected that. Just for testing, I made sure that the starting list was neither sorted by Text nor Value so that it would be obvious if it did get sorted.
  4. #4
    Ok, Dimitris pointed me the error also. I really thought I've tried with both 3.0 and latest SVN but for some reason I failed switching to SVN it seems :)

    Your override really fixes that on 3.1, my bad.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello Scott,

    Thank you for the report! Created an Issue:
    https://github.com/extnet/Ext.NET/issues/688

    Fixed in the revision 6319 (trunk). It goes to 3.1.0.

    Thank you for your fix. I used it in my fix with a small change - the sorting logic has been injected into a MultiCombo's onValueCollectionEndUpdate method rather than into bindStore.

Similar Threads

  1. MultiCombo and IE8
    By Birgit in forum 2.x Help
    Replies: 1
    Last Post: Dec 07, 2012, 9:15 AM
  2. selected value in MultiCombo
    By difa in forum 1.x Help
    Replies: 1
    Last Post: Dec 08, 2011, 1:30 PM
  3. Coolite.ext.web is having multicombo
    By Nagaraju in forum 1.x Help
    Replies: 1
    Last Post: Sep 23, 2011, 11:48 AM
  4. Select all in MultiCombo
    By skrishnasamy in forum 1.x Help
    Replies: 0
    Last Post: Aug 12, 2010, 7:00 AM

Posting Permissions