MultiCombo that Remember Selection through page

  1. #1

    MultiCombo that Remember Selection through page

    Hi,

    I resolve what i write in title my self.

    I post here my solution because i think could be implemented better by you.

    Scenario:
    Create a multicombo dynamically (in page init)
    Create and associate a store to multicombo (in page init)

    In my case i choose for remote page and sort for scalability reason but this is not important, also create in codebehind not is a need.

     Dim ComboBox as New Ext.Net.MultiCombo
     ComboBox.selectionMode = Ext.Net.MultiSelectMode.All
     ComboBox.id = "MyID"
     ComboBox.ID = FormField.@ID
     ComboBox.FieldLabel = "MyCombo"
     ComboBox.Triggers.Add(New Ext.Net.FieldTrigger With {.Icon = TriggerIcon.Clear, .HideTrigger = True})
     ComboBox.Listeners.TriggerClick.Handler = "if (index == 0) { this.clearValue(); this.triggers[0].hide(); }"
     ComboBox.Listeners.Select.Handler = "this.triggers[0].show();"
    
     Dim Store As New Ext.Net.Store
     Store.RemotePaging = True
     Store.RemoteSort = True
     Store.BaseParams.Add(New Ext.Net.Parameter With {.Name = "start", .Value = "0", .Mode = ParameterMode.Raw})
     Store.BaseParams.Add(New Ext.Net.Parameter With {.Name = "limit", .Value = "10", .Mode = ParameterMode.Raw})
     Store.Proxy.Add(New Ext.Net.PageProxy)
     Store.AutoLoad = False
     AddHandler Store.RefreshData, AddressOf MultiBoxStore_RefreshData
    
     Dim StoreReader As New JsonReader
     StoreReader.Fields.Add(New Ext.Net.RecordField("Display", RecordFieldType.String))
     StoreReader.Fields.Add(New Ext.Net.RecordField("Value", RecordFieldType.String))
     Store.Reader.Add(StoreReader)
    
     ComboBox.DisplayField = "Display"
     ComboBox.ValueField = "Value"
     ComboBox.PageSize = Integer.Parse(FormField.@PageSize)
     ComboBox.Store.Add(Store)
    
     Container.Items.Add(ComboBox)
    After try about two day a way to save/remember selection when i change page for scroll into data and nothing goes (viewstate,session,js script,etc.) i realize that there some limitation by control design to preselect items; what i understand is that if i can reinsert my previous selected item into store dataitems all goes right without complicated solution.

    Here is what i do in RefreshData event

     Private Sub MultiBoxStore_RefreshData(sender As Ext.Net.Store, e As Ext.Net.StoreRefreshDataEventArgs)     
            Dim DataSource As New List(Of MyEntityClass)
    
            If TypeOf sender.Parent Is Ext.Net.MultiCombo Then
                For Each Item In CType(sender.Parent, Ext.Net.MultiCombo).SelectedItems
                    DataSource.Add(New MyEntityClass With {.Display = Item.Text, .Value = Item.Value})
                Next
            End If
    
            Dim OnlySelectedValues = (From Record In DataSource Select Record.Value Distinct).ToList
            Dim MyDataBaseDataPaged = (From Record In DataContext.MyEntityClass Skip e.Start Take e.Limit).ToList
            Dim ItemsToAdd = From Record In MyDataBaseDataPaged Where Not OnlySelectedValues.Contains(Record.Value) 'For not repeat twice same item
    
            'Is a separator for userfriendly look, the "," in value help me to render unselectable this item
            DataSource.Add(New MyEntityClass With {.Value = ",", .Display = "<i>-- Items already selected --</i>"})
    
            DataSource.AddRange(ItemsToAdd)
    
            sender.DataSource = DataSource
    
            e.Total = DataContext.MyEntityClass.Count
    
        End Sub
    How you can see is a very simple solution for a complex problem, what i ask to you is to give us this possibility by control design and a new listitem type for render separator without create complex template layout

    For any question i'm here for you
  2. #2
    Hi,

    Thanks for sharing.

    Do you mind to move the thread to the Examples and Extras forum?
    http://forums.ext.net/forumdisplay.p...les-and-Extras

Similar Threads

  1. Replies: 1
    Last Post: Dec 04, 2012, 8:46 AM
  2. [CLOSED] MultiCombo selection via script
    By softmachine2011 in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Sep 21, 2012, 12:44 PM
  3. Replies: 0
    Last Post: Sep 19, 2011, 11:11 AM
  4. [CLOSED] Remember User name and Password
    By vedagopal2004 in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 12, 2011, 1:52 PM
  5. selection changes when clicked to next page
    By aniketyadav7 in forum 1.x Help
    Replies: 11
    Last Post: Dec 10, 2010, 9:33 AM

Tags for this Thread

Posting Permissions