From 75204229b22d374902776075e3f3ca8ac0be694f Mon Sep 17 00:00:00 2001 From: bseddon Date: Fri, 9 Nov 2018 14:48:30 +0000 Subject: [PATCH 1/9] Added alternative PivotUI2 PivotUI generates HTML using a table which has a fixed layout. The alternative UI generates a set of
tags. The presentation of these tags can be defined using only CSS. The updated ./dist/pivot.css includes CSS that create a facsimile of the table presentation. The facsimile is not exactly the same but it can be with a little more effort. --- src/pivot.coffee | 392 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 392 insertions(+) diff --git a/src/pivot.coffee b/src/pivot.coffee index 45c28261..624ce86e 100644 --- a/src/pivot.coffee +++ b/src/pivot.coffee @@ -1044,6 +1044,398 @@ callWithJQuery ($) -> @html opts.localeStrings.uiRenderError return this + + ### + Pivot Table UI2: calls Pivot Table core above with options set by user. + It is different to PivotUI in that it generates HTML using
tag + rather than a table. This means the table presentation can be more flexible. + ### + + $.fn.pivotUI2 = (input, inputOpts, overwrite = false, locale="en") -> + locale = "en" if not locales[locale]? + defaults = + derivedAttributes: {} + aggregators: locales[locale].aggregators + renderers: locales[locale].renderers + hiddenAttributes: [] + hiddenFromAggregators: [] + hiddenFromDragDrop: [] + menuLimit: 500 + cols: [], rows: [], vals: [] + rowOrder: "key_a_to_z", colOrder: "key_a_to_z" + dataClass: PivotData + exclusions: {} + inclusions: {} + unusedAttrsVertical: 85 + autoSortUnusedAttrs: false + onRefresh: null + showUI: true + filter: -> true + sorters: {} + + localeStrings = $.extend(true, {}, locales.en.localeStrings, locales[locale].localeStrings) + localeDefaults = + rendererOptions: {localeStrings} + localeStrings: localeStrings + + existingOpts = @data "pivotUIOptions" + if not existingOpts? or overwrite + opts = $.extend(true, {}, localeDefaults, $.extend({}, defaults, inputOpts)) + else + opts = existingOpts + + try + # do a first pass on the data to cache a materialized copy of any + # function-valued inputs and to compute dimension cardinalities + attrValues = {} + materializedInput = [] + recordsProcessed = 0 + PivotData.forEachRecord input, opts.derivedAttributes, (record) -> + return unless opts.filter(record) + materializedInput.push(record) + for own attr of record + if not attrValues[attr]? + attrValues[attr] = {} + if recordsProcessed > 0 + attrValues[attr]["null"] = recordsProcessed + for attr of attrValues + value = record[attr] ? "null" + attrValues[attr][value] ?= 0 + attrValues[attr][value]++ + recordsProcessed++ + + #start building the output + uiTable = $("
", "class": "pvtUi pvtUi2").attr("cellpadding", 5) + + #renderer control + rendererControl = $("
").addClass("pvtUiCell") + + renderer = $("", {type: "text"}).appendTo(controls) + .attr({placeholder: placeholder, class: "pvtSearch"}) + .bind "keyup", -> + filter = $(this).val().toLowerCase().trim() + accept_gen = (prefix, accepted) -> (v) -> + real_filter = filter.substring(prefix.length).trim() + return true if real_filter.length == 0 + return Math.sign(sorter(v.toLowerCase(), real_filter)) in accepted + accept = + if filter.indexOf(">=") == 0 then accept_gen(">=", [1,0]) + else if filter.indexOf("<=") == 0 then accept_gen("<=", [-1,0]) + else if filter.indexOf(">") == 0 then accept_gen(">", [1]) + else if filter.indexOf("<") == 0 then accept_gen("<", [-1]) + else if filter.indexOf("~") == 0 then (v) -> + return true if filter.substring(1).trim().length == 0 + v.toLowerCase().match(filter.substring(1)) + else (v) -> v.toLowerCase().indexOf(filter) != -1 + + valueList.find('.pvtCheckContainer p label span.value').each -> + if accept($(this).text()) + $(this).parent().parent().show() + else + $(this).parent().parent().hide() + controls.append $("
") + $("