[FIXED] [#672] [3.2.0] Set selection model to multi when there is one record selected

Page 1 of 2 12 LastLast
  1. #1

    [FIXED] [#672] [3.2.0] Set selection model to multi when there is one record selected

    On the following example proceed through the following steps:
    1. Select a record
    2. Click on Set Selection Mode to Multi button
    3. Hold SHIFT key and select another record. Error - It does not select the specified range.


    Everything works as expected when selection mode is set to multi prior selecting first record.
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <script type="text/javascript">
            var SetSelectionModeToMulti = function () {
                App._grd.selModel.setSelectionMode("MULTI");
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" ScriptMode="Debug" runat="server" />
        <ext:Button Text="Set Selection Mode to Multi" runat="server">
            <Listeners>
                <Click Handler="SetSelectionModeToMulti();" />
            </Listeners>
        </ext:Button>
        <br />
        <ext:GridPanel ID="_grd" runat="server" Title="Records" Frame="false" Width="500" Height="500">
            <Store>
                <ext:Store AutoLoad="true" ID="_str" runat="server">
                    <Proxy>
                        <ext:AjaxProxy Url="~/Example/LoadFakeRecords/">
                            <ActionMethods Read="POST" />
                            <Reader>
                                <ext:JsonReader RootProperty="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model IDProperty="ID" runat="server">
                            <Fields>
                                <ext:ModelField Name="ID" Type="String" />
                                <ext:ModelField Name="Name" Type="String" />
                                <ext:ModelField Name="LastName" Type="String" />
                                <ext:ModelField Name="Address" Type="String" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Text="ID" DataIndex="ID" runat="server" />
                    <ext:Column Text="Name" Flex="1" DataIndex="Name" runat="server" />
                    <ext:Column Text="Last Name" DataIndex="LastName" runat="server" />
                    <ext:Column Text="Address" DataIndex="Address" runat="server" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:CheckboxSelectionModel Mode="Single" runat="server" />
            </SelectionModel>
        </ext:GridPanel>
    </body>
    </html>
    namespace SandBox.Controllers
    {
        public class ExampleController : System.Web.Mvc.Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public StoreResult LoadFakeRecords()
            {
                List<Entity> lst = new List<Entity>();
    
                for (int index = 0; index < 15; index++)
                {
                    lst.Add(new Entity
                    {
                        ID = index,
                        Name = string.Format("Name - {0}", index),
                        LastName = string.Format("Last Name - {0}", index),
                        Address = string.Format("Address - {0}", index)
                    });
                }
    
                return new StoreResult(lst, lst.Count());
            }
        }
    
        [Serializable]
        public class Entity
        {
            public int ID { get; set; }
    
            public string Name { get; set; }
    
            public string LastName { get; set; }
    
            public string Address { get; set; }
        }
    }
    Last edited by Daniil; Jun 23, 2015 at 3:54 PM. Reason: [FIXED] [#672] [3.2.0]
  2. #2
    You can also reproduce this by:

    1. Clicking the multiMode change button (regardless of selecting an item or not).
    part 1: make your selection
    2. clicking one item
    3. holding shift
    4. clicking another item (above or below)
    5. releasing shift
    part 2: lose focus and try again
    6. click anywhere outside the grid frame (lose the focus to the grid)
    7. try repeating steps 3-5 to extend/shrink selection

    In other words, this another sample suggests the behavior is not a problem due to the button or the method called: it is a problem due to losing focus to the control.

    Notice how you can keep up with your selection if you hold CTRL while selecting, and also while you hold CTRL+SHIFT (to select a segment of the last item you selected).
    For example:
    1. Click item 1.
    2. hold shift, and click item 4 (you'll select 1 thru 4)
    3. release shift
    4. hold ctrl, and click item 7.
    5. without releasing ctrl, hold also shift, and click item 12.

    Voila, two segments. You may click outside (to lose focus) and then, with ctrl held, click back without losing your selection. And then continue.

    So, what do you think, does this make sense?

    EDIT:
    Reproducible on ExtJS example (grid with multi select): Grid with Buffered Store.
    Not reproducible on ExtJS example (multiselect control ditto): MultiSelect & ItemSelector
    Last edited by fabricio.murta; Feb 03, 2015 at 4:17 AM.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    1. Clicking the multiMode change button (regardless of selecting an item or not).
    part 1: make your selection
    2. clicking one item
    3. holding shift
    4. clicking another item (above or below)
    5. releasing shift
    part 2: lose focus and try again
    6. click anywhere outside the grid frame (lose the focus to the grid)
    7. try repeating steps 3-5 to extend/shrink selection
    It's due NavitationModel's previousRecord

    On SelectionModel's onNavigate, SelectionModel's selectionStart receives the instance of NavitationModel's previousRecord, which is null, as shown below:

    from = (me.selectionStart && me.isSelected(e.previousRecord)) ? me.selectionStart : (me.selectionStart = e.previousRecord)
    So, what do you think, does this make sense?
    Yes.
  4. #4
  5. #5
  6. #6
    Hello Raphael.

    Wow you really come ahead with a solution for the matter.

    But well, I see a couple problems on your implementation. You're -always- basing on the last selected element. And that's breaking sequently made selections.

    In the other hand, your solution really hits where it hurts, just a little thinkering more and the issue is sorted out!

    See what it happens when you shift select 1-6 then continue expanding the selection to 9, 11 and 13 (always holding shift). It also happens when selecting from above to down. Maybe just a matter of checking whether the lastSelected row is really selected or not.

    But I really think the best of the best approaches here would be to build a MultiSelect component side by side with the panel, and see exactly why it works (and selectionModel doesn't) and then apply the same mechanism (reusing already present code) in the grid's selectionModel.

    At least to me, the MultiSelect component seemed very stable at what matters to multiple selections and could be used as a base for the fix.
    Fabrício Murta
    Developer & Support Expert
  7. #7
    Just by testing for a previous selection seems to have fixed the issue, totally.

    So your override would be changed to:
            Ext.define('Ext.selection.Model', {
    		override: 'Ext.selection.Model',
            	onNavigate: function (e) {
            		if (this.selectionMode == "MULTI" && e.previousRecord == null) {
            			var lastSelected = this.selected.last();
            			if (lastSelected != null) {
            				this.setSelectionStart(lastSelected);
            				e.previousRecord = lastSelected;
            			}
            		}
            		this.callParent(arguments);
            	}
            });
    Everything now seems to work fine. Notice the only thing I changed was adding the && e.previousRecord == null condition to the test.

    As a side note, when writing overrides, for some reason sencha advised (i've seen in some forums and so on) us to use the above Ext.define and override: 'class' approach.

    Although your fix really does the job, I think I will still have at least a look on the MultiSelect component before applying anything to the code base.

    Again, thank you for the investigation and fix! That's much appreciated.
    Fabrício Murta
    Developer & Support Expert
  8. #8
    But I really think the best of the best approaches here would be to build a MultiSelect component side by side with the panel, and see exactly why it works (and selectionModel doesn't) and then apply the same mechanism (reusing already present code) in the grid's selectionModel.
    Although your fix really does the job, I think I will still have at least a look on the MultiSelect component before applying anything to the code base.
    Checkbox Selection Model is a Multi Select component. There is no need to build a new one. Honestly, i just cant imagine the need for this, at all. If i am not wrong, it should be fixed.
    Last edited by RCN; Feb 03, 2015 at 10:18 PM.
  9. #9
    As a side note, when writing overrides, for some reason sencha advised (i've seen in some forums and so on) us to use the above Ext.define and override: 'class' approach.
    Can you share the link?
  10. #10
    I confirm that && e.previousRecord == null is required.

    Again, thank you for the investigation and fix! That's much appreciated.
    You're welcome
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 7
    Last Post: Sep 19, 2017, 11:27 PM
  2. Replies: 3
    Last Post: Dec 21, 2014, 9:29 PM
  3. [CLOSED] GridPanel selection model does not update, after adding record
    By RajivDutt in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: May 21, 2014, 5:03 AM
  4. Replies: 2
    Last Post: Aug 09, 2011, 10:38 AM
  5. Replies: 10
    Last Post: Nov 01, 2010, 11:33 AM

Posting Permissions