Skip to content

Commit 9d6db8f

Browse files
committed
Allowed editing of the opt and added onblur to refresh the pivot when changed.
1 parent 51e6ffc commit 9d6db8f

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

examples/onrefresh.html

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
<script type="text/javascript">
1616
$(function(){
1717
var derivers = $.pivotUtilities.derivers;
18+
var data;
1819

20+
var Refresh = function(config) {
21+
var config_copy = JSON.parse(JSON.stringify(config));
22+
//delete some values which are functions
23+
delete config_copy["aggregators"];
24+
delete config_copy["renderers"];
25+
delete config_copy["derivedAttributes"];
26+
//delete some bulky default values
27+
delete config_copy["rendererOptions"];
28+
delete config_copy["localeStrings"];
29+
$("#config_json").text(JSON.stringify(config_copy, undefined, 2));
30+
}
1931
var makePivot = function(mps) {
2032
$("#output").pivotUI(mps, {
2133
derivedAttributes: {
@@ -31,36 +43,37 @@
3143
// "src": "Create Date"
3244
// }
3345
// },
34-
onRefresh: function(config) {
35-
var config_copy = JSON.parse(JSON.stringify(config));
36-
//delete some values which are functions
37-
delete config_copy["aggregators"];
38-
delete config_copy["renderers"];
39-
delete config_copy["derivedAttributes"];
40-
//delete some bulky default values
41-
delete config_copy["rendererOptions"];
42-
delete config_copy["localeStrings"];
43-
$("#config_json").text(JSON.stringify(config_copy, undefined, 2));
44-
}
46+
onRefresh: Refresh
4547
});
4648
};
47-
4849
$.getJSON("mps.json", makePivot);
4950
$("#csv").bind("change", function(event){
5051
var reader = new FileReader();
5152
reader.onload = function(theFile) {
5253
try {
53-
var input = $.csv.toArrays(theFile.target.result);
54+
data = $.csv.toArrays(theFile.target.result);
5455

5556
}
5657
catch(e) {
5758
alert("CSV Parse error: " + e.message );
5859
return;
5960
}
60-
makePivot(input);
61+
makePivot(data);
6162
}
6263
reader.readAsText(event.target.files[0]);
6364
});
65+
66+
$("#config_json").bind("blur", function(event){
67+
var a = JSON.parse($(this).val());
68+
a.onRefresh=Refresh;
69+
a.renderers = $.extend(
70+
$.pivotUtilities.renderers,
71+
$.pivotUtilities.gchart_renderers,
72+
$.pivotUtilities.d3_renderers,
73+
$.pivotUtilities.jqwidgets_renderers
74+
);
75+
$("#output").pivotUI(data,a,true);
76+
});
6477
})
6578
</script>
6679
<p><a href="index.html">&laquo; back to examples</a></p>

0 commit comments

Comments
 (0)