1. #1
    Ext User
    Join Date
    May 2007
    Posts
    5
    Vote Rating
    0
    klodoma is on a distinguished road

      0  

    Default Add/Remove data from combobox

    Add/Remove data from combobox


    Hi to all,

    I have a combobox like in the example:
    Code:
    // some data used in the examples
    Ext.namespace('Ext.exampledata');
    
    Ext.exampledata.states = [
            ['AL', 'Alabama'],
            ['AK', 'Alaska'],
            ['AZ', 'Arizona'],
            ['AR', 'Arkansas'],
            ['CA', 'California'],
            ['CO', 'Colorado'],
            ['WY', 'Wyoming']
        ];
        
    Ext.onReady(function(){
    	
        // simple array store
        store = new Ext.data.SimpleStore({
            fields: ['id', 'value'],
            data : Ext.exampledata.states // from states.js
        });
        combo = new Ext.form.ComboBox({
            store: store,
            displayField:'value',
            valueField:'id',
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            emptyText:'Select a state...',
            selectOnFocus:true
        });
        combo.addListener('select', allert);
        combo.applyTo('local-states');
    How can I remove a row from this combo?

    I succeded to add values to this combo with the following code:
    Code:
    function onclick_add(){
    var myArray=new Array()
    	myArray['id'] = 'X';
    	myArray['value'] = 'XXX';
    	var rec = new Ext.data.Record(myArray);
    	combo.store.add(rec);
    }
    Please let me know if there is a more easy way to do it.

    But I could not find out how to remove the data from the store. My problem was that I could not figure out how to return the Ext.data.Record that is selected in the combobox.

    Any help apreciated.

  2. #2
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,523
    Vote Rating
    378
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Yes, your approach is right. There is store.remove() method for removing a record from the store.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  3. #3
    Ext User
    Join Date
    May 2007
    Posts
    5
    Vote Rating
    0
    klodoma is on a distinguished road

      0  

    Default


    Thanks for the quick answer.
    Quote Originally Posted by jsakalos View Post
    Yes, your approach is right. There is store.remove() method for removing a record from the store.
    Yes but store.remove() takes as parameter a Ext.data.Record record type value. How can I get this type of value from the combobox? I want to delete the selected combobox value.

    The solution that I've found is to save the index of the element on the combobox.select event and with this index to make the delete. But this includes the use of another variable.

    How can Ext.data.Record object be readed as being the selected combobox item?

  4. #4
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,523
    Vote Rating
    378
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    combo.store.remove(combo.store.getById(combo.getValue()));

    removes the currently selected item.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  5. #5
    Ext User
    Join Date
    May 2007
    Posts
    5
    Vote Rating
    0
    klodoma is on a distinguished road

      0  

    Default


    Hm... I tried this also before you posted and still not working. Am I not filling the store in the right way?

    combo.store.getById(combo.getValue()); is returning undefined.

    combo.getValue() is returning 'AK' if 'Alaska' is selected, somehow I habe to pass to combo.store.getById the ID if the selected element and not the value. Am I right?


    And... another question. I bind this combobox to a input field of text type with
    Code:
    combo.applyTo('local-states');
    where
    Code:
    <input type="text" id="local-states" size="20"/>
    this is the text type.

    If I select a combobox item, I would like the valueField of the combobox to be submitted on a page submit. This way that I made the displayField of the combobox is submitted. Can this be done automatically?

    (Sorry for all the questions, but I have the feeling there are many easy ways that I miss)

  6. #6
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,523
    Vote Rating
    378
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Re 1: I finally discovered where is the problem. You're using the in-memory data for store and id for records is auto generated in this case. So using store.getById() leads to undefined. The solution would be to use (undocumented) property of combo selectedIndex and then remove record like this:

    PHP Code:
    combo.store.remove(combo.store.getAt(combo.selectedIndex)); 

    Re 2: Also standard html select element does not submit currently displayed text but the value of the combo. If you need it you can include it options.params when submitting.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  7. #7
    Ext User
    Join Date
    May 2007
    Posts
    5
    Vote Rating
    0
    klodoma is on a distinguished road

      0  

    Thumbs up


    Quote Originally Posted by jsakalos View Post
    PHP Code:
    combo.store.remove(combo.store.getAt(combo.selectedIndex)); 
    Aha. I looked all over in the docs for that index. Perfect.

    About problem 2, I will play a little more an get back.


    Thank you for the help!

  8. #8
    Ext User
    Join Date
    Feb 2008
    Posts
    20
    Vote Rating
    0
    hazooma is on a distinguished road

      0  

    Default


    What if you want to remove the record from the comboBox itself, not from the store? I am using the store to populate two different comboBoxes, so I cannot afford to delete records from the store itself. Is this doable?

    Thanks!

  9. #9
    Ext JS Premium Member
    Join Date
    Jan 2008
    Posts
    315
    Vote Rating
    0
    josh803316 is on a distinguished road

      0  

    Default


    I'm having the same issue. I have combo boxes in a grid that are populated with row numbers. When I page the number of rows change so I want my combo boxes to change their list length, without deleting any actual records from the store.

  10. #10
    Ext User
    Join Date
    Jan 2009
    Posts
    132
    Vote Rating
    0
    ald_2008 is on a distinguished road

      0  

    Post


    Hi, I have a combo-box which let me select more than one entries,
    I want to display all of the selected values in a text box with a button click.
    How can i do that?
    Please help me with sample code.
    I been trying from last 2 days, and can't figure it out.
    Any help is appreciated.
    Thanks,