[CLOSED] Multiple items with same value on combobox

Hybrid View

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

    [CLOSED] Multiple items with same value on combobox

    I have a custom control that inherits from combobox. The problem is that it must be able to store different items with the same value and when this happens, when the user chooses any item with the same value the first item with this value always gets selected.

    Let?s say the store has these fields: _Value, _Display, Company, Branch

    _Value is defined as ValueField, and _Display as the DisplayField.

    And i load the combobox with these values:

    [_Value][_Display][Company][Branch]
    [001][001 - Rio de Janeiro][000][001]
    [002][002 - Goi?s][000][002]
    [001][001 - Filial 1][001][001]
    [002][002 - Filial 2][001][002]
    [XPTO][XPTO - Filial 00][KLH0][XPTO]

    The user can see all the values fine. But if he selects the row "[001][001 - Filial 1][001][001]", the display shown is "001 - Rio de Janeiro", from the row "[001][001 - Rio de Janeiro][000][001]", which is the first row with value "001".

    To solve this i've tried to override the method "findRecord" in many ways. The one that almost worked was this, where instead of finding the item only by it's value, i compare all of the rows:

        
    findRecord: function (prop, value) {
            var record;
            var thisObj = this;
            if (this.store.getCount() > 0) {
                this.store.each(function (r) {
    
                        var fitsValues = true;
                        var selectedIndexData = thisObj.getStore().data.items[thisObj.selectedIndex].data;
    
                        for (var i = 0; i < thisObj.getStore().fields.keys.length; i++) {
                            var currentField = thisObj.getStore().fields.keys[i];
                            if (r.data[currentField] != selectedIndexData[currentField]) {
                                fitsValues = false;
                            }
                        }
    
                        if (fitsValues && r.data[prop] == value) {
                            record = r;
                            return false;
                        }
                    
                });
            }
            return record;
        },
    It works perfectly when the user clicks on the combobox trigger and selects an item with the mouse. But when he types some filter text and selects an item with the keyboard, it won't work fine. The method findRecord is called many times, it's hard even to debug and figure out what's going on. I guess the problem is with the selectedIndex, that doesn't behave as well when in filter mode as when the user selects an item with the mouse.

    Any hint on how to make the combobox select the item the user chooses, instead of getting the item by (first) value? I'm stuck with this one..
    Last edited by Daniil; Sep 05, 2014 at 8:04 AM. Reason: [CLOSED]
  2. #2
    The following link should help with tips on providing code samples:

    http://forums.ext.net/showthread.php...ation-Required
    Geoffrey McGill
    Founder
  3. #3
    Please note that Combobox is not designed to work with multiple items with the same value
    Combo remembers value of selected item (not index or anything else), if value is not defined then text is considered as value

    So, value is considered as id and id should be unique
    Why don't you want to use inique values? For example, you can concatenate the value with some unique prefix
  4. #4
    Vladimir, because it's a custom control and it can be bound to legacy tables data which use composite keys, as in the example i provided, and it would be a burden to have to create artificial keys just to get the right text displayed in the combobox. Isn't there any way i can get the correct index of the selected item? Or to get the exact item that was selected in any event, so i can implement the comparison between values?
  5. #5
    Vladimir, because it's a custom control and it can be bound to legacy tables data which use composite keys, as in the example i provided, and it would be a burden to have to create artificial keys just to get the right text displayed in the combobox.
    Why artificial? You could concatenate those composite keys and use it as values.

    Isn't there any way i can get the correct index of the selected item? Or to get the exact item that was selected in any event, so i can implement the comparison between values?
    With a standard ComboBox component and with the same values? I think the answer is "no". A ComboBox doesn't support same values for different items. You could try to override/extend the ComboBox class, but it might be quite a challenge task.
  6. #6
    Hi Daniil. I'm already extending combobox. I have overriden a lot of functions to make it work the way i need. That's the only point missing, the items with same values. Of course i could concatenate the values of the keys, but then, at every place where the value is used, the developers would need to have this checking over wether it's a raw value or a concatenated value, splitting the concatenated value, etc. The control is used in a lot of places. I mean, it's a lot of work for a simple thing. If i could solve this at the control level, i'd spare a lot of time.

    As i said in the first post, i've already achieved to make things work for when user clicks an item, overriding the combobox function "findRecord". But the user can type and search for a value also, and in this case i can't get the correct index which was selected. I just need some help to figure out what functions i need to override to get the correct index / record that was selected, and store it somewhere, so that i could use it in findRecord to compare with the items in the store and select the correct item, so that the correct text is shown.

    Sorry about the lack of an example, but it's hard to create an example for this, there are a lot of classes involved, it's bound to database, etc, and i guess it would not be of much help.

Similar Threads

  1. Replies: 4
    Last Post: Jul 15, 2014, 10:59 AM
  2. DragDrop multiple items at a time
    By Rupesh in forum 1.x Help
    Replies: 0
    Last Post: Nov 28, 2013, 9:50 AM
  3. Multiple Clicking on tree shows multiple items
    By yash.kapoor in forum 2.x Help
    Replies: 1
    Last Post: Oct 16, 2012, 7:44 AM
  4. Treepanel multiple items drag&drop
    By marcozzz in forum 1.x Help
    Replies: 0
    Last Post: Jul 15, 2010, 2:39 PM

Posting Permissions