PDA

View Full Version : Deleting Combo Box Record(s)



dwb
12 Mar 2012, 8:25 AM
Hello - I'm having a heck of a time deleting a record from a combo box. The combo box is simple, it's contains 2 static (locally assigned) items (records). Below is combo-box and store code:

Combo-box:
Ext.define('Nile.view.layout.BillPlanCombox', {
requires: ['Nile.store.BillPlanComboxStore'],

extend: 'Ext.form.ComboBox',

alias: 'widget.billplancombox',

id: 'BillPlanCombox',

fieldLabel: 'Events',

labelAlign : 'left',

labelWidth: 55,

store: 'BillPlanComboxStore',

queryMode: 'local',

triggerAction: 'all',

editable: false,

displayField: 'name',

valueField: 'eventVal',




listeners:{

afterrender: function(){

this.select(0); //always select 1st item - this doesn't work after "remove"
}

},




initComponent: function() {

Ext.applyIf(this, {});

this.callParent(arguments);

}
});

Combo-box Store:
Ext.define('Nile.store.BillPlanComboxStore', {
extend: 'Ext.data.Store',

storeId:'BillPlanComboxStore',

fields: ['eventVal', 'name'],

data : [

{eventVal:0, name:'Start Enrollment'},

{eventVal:1, name:'End Enrollment'},

]
});

What I'm trying to accomplish is as follows:
The User selects a single option from our combo-box. This User selection is passed to another component just fine. Next, and here's were I'm having difficulties, I want to remove the selected combo-box record so that the User can not select it again. Here's the code from the controller that does the "Remove " from the combo-box's store:

Controller:
//remove selected record from store
bpComboStore.removeAt(comboRecVal); //record values were setup to match record index values
bpComboStore.sync();
console.log('there are '+ bpComboStore.getTotalCount() +'records left in the combox.');


The results of the removal have me baffled. The record seems to removed ... but I don't think it really is deleted because the display value disappears and an empty row is left behind - if the record was really removed, then why the blank row? If I reload the store, guess what, the deleted record is recovered, so, the record was not deleted to begin with, was it hidden?

So, it's obvious that "remove" doesn't do what I thought it did. So, how does one actually remove a record from a local store?

Thanks for the help,
-dwb

Farish
12 Mar 2012, 10:16 AM
after deleting the record, print the following in Firebug console:


store.getRemovedRecords();

the problem could be in how you get the value in comboRecVal

dwb
12 Mar 2012, 12:23 PM
Thanks for the tip!

I've done this only to discover that NO records are being deleted.

So, instead of using my var (comboRecVal) I've substituted 0 (zero). Thus, I've hard coded that the first record in the store to be deleted. The result is the same, there are no records removed from the store and the store's "getTotalCount();" still returns 2 (the original number of records I started out with).

Maybe there's some sort of commit? Perhaps the records are flagged for deletion and waiting to update the store? No - that couldn't be because the deleted records function still returns none.... I'm lost.

Farish
12 Mar 2012, 12:27 PM
Hmmm. you should remove the comma after your second record. that might cause some problems specially in IE.

What you could try is this:


store.remove(store.getAt(0));
console.log(store.getRemovedRecords());

Farish
12 Mar 2012, 12:45 PM
yup. it appears that there is something wrong with your store and/or combobox.

dwb
12 Mar 2012, 12:45 PM
Ah, I see...

I made another attempt but I'm still getting identical results.

This is what my controller is calling now:

bpComboStore.remove(bpComboStore.getAt(0));
bpComboStore.sync();


console.log(bpComboStore.getRemovedRecords());
console.log('there are '+ bpComboStore.getTotalCount() +' records left in the combox.');

The above code returns:
[ ]
there are 2 records left in the combox.

Something is weird perhaps with my store... I'm going to reconfigure the store to be an ArrayStore and see if it makes any difference.

Thanks again for your time and attention.