From e28294457416c33f8901bbb2ed8cd5d8e1c566e8 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Mon, 23 Apr 2012 15:27:35 -0400 Subject: [PATCH] Add simple way to reprocess the display fields and filters. --- index.html | 10 +++++----- jquery_pivot.js | 26 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 8ac23eb..4cace95 100644 --- a/index.html +++ b/index.html @@ -103,7 +103,7 @@

Pivot.js

@@ -198,15 +198,15 @@

Results

// **Sexy** In your console type pivot.config() to view your current internal structure (the full initialize object). Pass it to setup and you have a canned report. $('#ar-aged-balance').click(function(event){ - setupPivot({"url":'./lib/csv/demo.csv', "fields": fields, "filters":{},"rowLabels":["employer"],"columnLabels":["age_bucket"],"summaries":["balance"]}) + $('#pivot-demo').pivot_display('reprocess_display', {rowLabels:["employer"], columnLabels:["age_bucket"], summaries:["balance"]}) }); $('#acme-detail-report').click(function(event){ - setupPivot({"url":'./lib/csv/demo.csv', "fields": fields, "filters":{"employer":"Acme Corp"},"rowLabels":["city","last_name","first_name","state","invoice_date"],"columnLabels":[],"summaries":[]}) + $('#pivot-demo').pivot_display('reprocess_display', {filters:{"employer":"Acme Corp"},rowLabels:["city","last_name","first_name","state","invoice_date"]}) }); - $('#jacksonville-invoice-detail').click(function(event){ - setupPivot({"url":'./lib/csv/demo.csv', "fields": fields, "filters":{"city":"Jacksonville"},"rowLabels":["last_name","first_name","employer","invoice_date"],"columnLabels":[],"summaries":["payment_amount"]}) + $('#miami-invoice-detail').click(function(event){ + $('#pivot-demo').pivot_display('reprocess_display', {"filters":{"city":"Miami"},"rowLabels":["last_name","first_name","employer","invoice_date"],"summaries":["payment_amount"]}) }); }); \ No newline at end of file diff --git a/jquery_pivot.js b/jquery_pivot.js index c39546d..7a17170 100644 --- a/jquery_pivot.js +++ b/jquery_pivot.js @@ -28,11 +28,7 @@ var methods = { if (options.skipBuildContainers === undefined || options.skipBuildContainers === false) self.build_containers(); - self.build_toggle_fields('#row-label-fields', pivot.fields().rowLabelable, 'row-labelable'); - self.build_toggle_fields('#column-label-fields', pivot.fields().columnLabelable, 'column-labelable'); - self.build_toggle_fields('#summary-fields', pivot.fields().summarizable, 'summary'); - - methods.build_filter_list(); + self.populate_containers(); $('.row-labelable').change(function(event) { self.update_label_fields('row'); @@ -75,6 +71,26 @@ var methods = { } }); }, + populate_containers: function(){ + methods.build_toggle_fields('#row-label-fields', pivot.fields().rowLabelable, 'row-labelable'); + methods.build_toggle_fields('#column-label-fields', pivot.fields().columnLabelable, 'column-labelable'); + methods.build_toggle_fields('#summary-fields', pivot.fields().summarizable, 'summary'); + methods.build_filter_list(); + }, + reprocess_display : function(options){ + if (options.rowLabels === undefined) options.rowLabels = []; + if (options.columnLabels === undefined) options.columnLabels = []; + if (options.summaries === undefined) options.summaries = []; + if (options.filters === undefined) options.filters = {}; + + pivot.filters().set(options.filters); + pivot.display().summaries().set(options.summaries); + pivot.display().rowLabels().set(options.rowLabels); + pivot.display().columnLabels().set(options.columnLabels); + + methods.populate_containers(); + methods.update_results(); + }, build_containers : function(){ var containers = '
' +