View Full Version : How to add a record to a store and make it the default

3 Jun 2014, 7:28 AM
Hello All,

I have a combo box and for loading the combo box, I am using a store as shown below and everything is working fine. Now While loading, I need to do a extra check and if the condition satisfies I need to add a record dynamically to the store and make that record to be the default value in the combo box.

loadBookStatus: function(form, name, bookDetail, bookCode) {
var f = Ext.String.format('field[name={0}]', name);
var bookCpt = form.down(f);
var bookStore = bookCpt.getStore();
bookStore .removeAll();
url: MyBook.BookHelper.getBaseUrl() + 'bookOrder/getBookStatus',
method: 'POST',
params: {
bookCode: bookCode
success: function(response, opt) {
var list = Ext.decode(response.responseText).data;
// now for all items in the list, place in the store
bookStore.loadData(list, false);

// Below is the code that I am adding now to satisfy a new condition.
var statusCode = bookStore.find('bookCd', bookDetail.bookCd, null, null, null, true );
if(statusCode == -1){
bookCd: 'NEW',
bookTypeCd: '',
description : bookDetail.getBookDescription(),
bookCompleteStatus: '',
requiredStatus: ''
}) ;

// New code ends.

Here Before adding this new condition, everything is working fine as it should be. The combo box displays the bookCd and the description values. After adding the code also, everything is working fine but I am not seeing the new record anywhere in the combo box and the combo box is not selecting any default value.. Not sure what I am missing. Please let me know how I can do this.

Mark Wagoner
4 Jun 2014, 4:03 AM
I'm not positive but I think the record that you are adding to the store has to be an instance of a data model. Try creating and populating a model object and adding that to the store.