Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dgrid does not correctly update Stateful objects from _StoreMixin#save #563

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions _StoreMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,16 @@ function(kernel, declare, lang, Deferred, listen, aspect, put){
var colsWithSet = self._columnsWithSet,
updating = self._updating,
key, data;
// Copy dirty props to the original, applying setters if applicable
for(key in dirtyObj){
object[key] = dirtyObj[key];

if (object.set && typeof object.set === "function") {
object.set(dirtyObj);
} else {
// Copy dirty props to the original, applying setters if applicable
for(key in dirtyObj){
object[key] = dirtyObj[key];
}
}

// Apply any set methods in column definitions.
// Note that while in the most common cases column.set is intended
// to return transformed data for the key in question, it is also
Expand Down
84 changes: 84 additions & 0 deletions test/editor_stateful.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Stateful Editing</title>
<meta name="viewport" content="width=570">
<style>
@import "../../dojo/resources/dojo.css";
@import "../../dijit/themes/claro/claro.css";
@import "../css/skins/claro.css";
</style>
<script src="../../dojo/dojo.js"
data-dojo-config="async: true, isDebug: true"></script>
<script>
require([
"dojo/_base/declare",
"dojo/store/Memory",
"dijit/_WidgetBase",
"dgrid/OnDemandGrid",
"dgrid/editor",
"dgrid/test/data/base"
], function (declare, Memory, _WidgetBase, OnDemandGrid, editor) {
var State = declare(_WidgetBase, {
_setAbbreviationAttr: function (abbreviation) {
console.log("abbreviation updating from", this.abbreviation, "to", abbreviation);
this.abbreviation = abbreviation;
},
_setNameAttr: function (name) {
console.log("name updating from", this.name, "to", name);
this.name = name;
}
});

function createStore() {
var data = [],
states = testStateStore.data,
state, i, total;

for (i = 0, total = states.length; i < total; i++) {
state = states[i];

data.push(
new State({
abbreviation: state.abbreviation,
name: state.name
})
);
}

return new Memory({
data: data,
idProperty: "abbreviation"
});
}

window.grid = new OnDemandGrid({
store: createStore(),
columns: [
editor({
label: "Abbreviation",
field: "abbreviation",
editor: "text",
editOn: "dblclick"
}),
editor({
label: "Name",
field: "name",
editor: "text",
editOn: "dblclick"
})
]
}, "grid");

grid.startup();
});
</script>
</head>
<body class="claro">
<h2>Editor with Stateful objects</h2>
(This test requires dojo and dijit to be installed)
<div id="grid"></div>
<button type="button" id="save" onclick="grid.save()">Save</button>
</body>
</html>