PDA

View Full Version : [CLOSED] Grid with changes to store items not refreshing on commitChanges



ptrourke
Jul 11, 2013, 6:32 PM
Kindergarten question here. Sorry, I tried searching for this on the forums and examples but couldn't find it.

I have a grid called SelectedCompanyClasses. This displays the company classes that I want to work with. Each company class belongs to one and only one CompanyGroup. The selection model for this grid is SelectedCompanyClassesSelectionModel.

I have a SelectBox called ChangeToCompanyGroupName bound to the store CompanyGroupBinStore.

I have a button called MoveToGroup that has a listener with a click event; this calls the function CompanyGroupSelector.MoveToCompanyGroup.

I have other JavaScript functions that are called in various other ways, including two, AddToCompanyGroup and RemoveFromCompanyGroup.

When my listeners call my AddToCompanyGroup and RemoveFromCompanyGroup functions, the selected Classes are immediately added to or removed from the grid on the screen. These work as expected.

When my listener calls MoveToCompanyGroup, the update to the store does not appear in the grid. If I click on a column name to change the sort order on the grid, though, it does update.

I'm probably missing something obvious to update the grid. I tried .render() (though from things you've said previously I've gathered this should not be necessary), and I've tried adding App.SelectedCompanyClasses.store.save(myRecord) (and that did not work, either).

If you need to see the ASPX markup, let me know.



var SelectedCompanyClassHasSelection = function() {return App.SelectedCompanyClassesSelectionModel.hasSelect ion();};

var CompanyGroupSelector = {

AddToCompanyGroup: function() {
[additional logic]
App.SelectedCompanyClasses.store.add({CompanyGroup ID = NewCompanyGroupID, CompanyGroupName = NewCompanyGroupName, CompanyClassID: NewCompanyClassID, CompanyClassName: NewCompanyClassName});
App.SelectedCompanyClasses.store.commitChanges();
App.SelectedCompanyClasses.show();
},

RemoveFromCompanyGroup: function() {
var currentRecord = App.SelectedCompanyClasses.getSelectionModel().get LastSelected();
App.SelectedCompanyClasses.store.remove(currentRec ord);
App.SelectedCompanyClasses.store.commitChanges();
App.SelectedCompanyClasses.show();
},

MoveToCompanyGroup: function() {
if (SelectedCompanyClassHasSelection) {
var CompanyClassList = App.SelectedCompanyClasses.getRowsValues({selected Only: true});
var myStore = App.SelectedCompanyClasses.store;
var binStore = App.CompanyGroupBinStore;
var NewCompanyGroupID = App.ChangeToCompanyGroupName.value;
var myCompanyGroupRecord = binStore.getById(NewCompanyGroupID);
var NewCompanyGroupName = myCompanyGroupRecord.data.CompanyGroupName;
Ext.each(CompanyClassList, function(item){
var myRecord = myStore.getById(item.CompanyClassID);
myRecord.data.CompanyGroupID = NewCompanyGroupID;
myRecord.data.CompanyGroupName = NewCompanyGroupName;
// App.SelectedCompanyClasses.store.save(myRecord); //Adding this line did not help
});

App.SelectedCompanyClasses.store.commitChanges();
// App.SelectedCompanyClasses.render(); //Adding this line, which I gather is not recommended, did not help.
App.SelectedCompanyClasses.show();
};
}
};

Baidaly
Jul 11, 2013, 11:28 PM
Hello!

I guess you forgot braces to call your method SelectedCompanyClassHasSelection:


MoveToCompanyGroup: function() {
if (SelectedCompanyClassHasSelection()) {

Also, you should use set method instead of setting fields directly: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Model-method-set

ptrourke
Jul 12, 2013, 12:55 AM
Hello!

I guess you forgot braces to call your method SelectedCompanyClassHasSelection:


MoveToCompanyGroup: function() {
if (SelectedCompanyClassHasSelection()) {


Thanks, but that's not the problem ;-).



Also, you should use set method instead of setting fields directly: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Model-method-set

Thanks, I didn't realize that .set() was a method of this object. I had tried .setValue() and it said that was not a member of the object.

Will that resolve this problem? In the debugger, it seemed that the assignment operator worked.

Baidaly
Jul 12, 2013, 1:15 AM
Thanks, I didn't realize that .set() was a method of this object. I had tried .setValue() and it said that was not a member of the object.

Will that resolve this problem? In the debugger, it seemed that the assignment operator worked.

When you change properties of some record directly, the record is not marked as changed (dirty). So you should use set method. If it wouldn't help please provide full sample.

ptrourke
Jul 12, 2013, 2:12 AM
When you change properties of some record directly, the record is not marked as changed (dirty). So you should use set method. If it wouldn't help please provide full sample.

AH. Thanks, that makes sense. I'll try it first thing in the morning.

PTR

ptrourke
Jul 12, 2013, 3:17 PM
AH. Thanks, that makes sense. I'll try it first thing in the morning.

PTR


Yep, changing the lines



myRecord.data.CompanyGroupID = NewCompanyGroupID;
myRecord.data.CompanyGroupName = NewCompanyGroupName;


to the following



myRecord.set("CompanyGroupID", NewCompanyGroupID);
myRecord.set("CompanyGroupName", NewCompanyGroupName);


fixed it. Thanks! Please close.