Skip to content

Commit

Permalink
Fix issue with missing field values.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Jackson committed Apr 6, 2012
1 parent 27b8440 commit 9c8c570
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
22 changes: 17 additions & 5 deletions pivot.js
Expand Up @@ -28,12 +28,9 @@ function reset(){
}; };


function config(){ function config(){
var fieldsOutput = getFields(), i = -1, m = fieldsOutput.length;
while (++i < m){
delete fieldsOutput[i].values;
}


return { fields: fieldsOutput,
return { fields: cloneFields(),
filters: filters, filters: filters,
rowLabels: objectKeys(displayFields.rowLabels), rowLabels: objectKeys(displayFields.rowLabels),
columnLabels: objectKeys(displayFields.columnLabels), columnLabels: objectKeys(displayFields.columnLabels),
Expand Down Expand Up @@ -374,6 +371,7 @@ function pivotFields(type){
summarizable: restrictFields('summarizable'), summarizable: restrictFields('summarizable'),
filterable: restrictFields('filterable'), filterable: restrictFields('filterable'),
pseudo: restrictFields('pseudo'), pseudo: restrictFields('pseudo'),
clone: cloneFields,
add: appendField, add: appendField,
all: getFields, all: getFields,
set: setFields, set: setFields,
Expand All @@ -395,6 +393,20 @@ function pivotFields(type){
} }
}; };


function cloneFields(){
var fieldsOutput = [];
for (var field in fields){
var newField = {};
for (var key in fields[field]){
if (fields[field].hasOwnProperty(key) && key !== 'values')
newField[key] = fields[field][key];
}
fieldsOutput.push(newField);
}

return fieldsOutput;
}

function getFields(){ function getFields(){
var retFields = []; var retFields = [];
for (var key in fields) { for (var key in fields) {
Expand Down
2 changes: 1 addition & 1 deletion pivot.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/pivotjs_spec.js
Expand Up @@ -40,7 +40,7 @@ describe('pivot', function () {
initialColumnLabels = pivot.utils().objectKeys(pivot.display().columnLabels().get), initialColumnLabels = pivot.utils().objectKeys(pivot.display().columnLabels().get),
initialSummaries = pivot.utils().objectKeys(pivot.display().summaries().get), initialSummaries = pivot.utils().objectKeys(pivot.display().summaries().get),
initialFilters = pivot.filters().all(), initialFilters = pivot.filters().all(),
initialFields = pivot.fields().all(); initialFields = pivot.fields().clone();


expect(pivot.config()).toEqual({ fields: initialFields, expect(pivot.config()).toEqual({ fields: initialFields,
filters: initialFilters, filters: initialFilters,
Expand Down
15 changes: 15 additions & 0 deletions src/fields.js
Expand Up @@ -5,6 +5,7 @@ function pivotFields(type){
summarizable: restrictFields('summarizable'), summarizable: restrictFields('summarizable'),
filterable: restrictFields('filterable'), filterable: restrictFields('filterable'),
pseudo: restrictFields('pseudo'), pseudo: restrictFields('pseudo'),
clone: cloneFields,
add: appendField, add: appendField,
all: getFields, all: getFields,
set: setFields, set: setFields,
Expand All @@ -26,6 +27,20 @@ function pivotFields(type){
} }
}; };


function cloneFields(){
var fieldsOutput = [];
for (var field in fields){
var newField = {};
for (var key in fields[field]){
if (fields[field].hasOwnProperty(key) && key !== 'values')
newField[key] = fields[field][key];
}
fieldsOutput.push(newField);
}

return fieldsOutput;
}

function getFields(){ function getFields(){
var retFields = []; var retFields = [];
for (var key in fields) { for (var key in fields) {
Expand Down
7 changes: 2 additions & 5 deletions src/init.js
Expand Up @@ -27,12 +27,9 @@ function reset(){
}; };


function config(){ function config(){
var fieldsOutput = getFields(), i = -1, m = fieldsOutput.length;
while (++i < m){
delete fieldsOutput[i].values;
}


return { fields: fieldsOutput,
return { fields: cloneFields(),
filters: filters, filters: filters,
rowLabels: objectKeys(displayFields.rowLabels), rowLabels: objectKeys(displayFields.rowLabels),
columnLabels: objectKeys(displayFields.columnLabels), columnLabels: objectKeys(displayFields.columnLabels),
Expand Down

0 comments on commit 9c8c570

Please sign in to comment.