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

add number format to pivot table #2703

Merged
merged 13 commits into from
May 12, 2017
Merged
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
6 changes: 2 additions & 4 deletions superset/assets/backendSync.json
Original file line number Diff line number Diff line change
Expand Up @@ -1328,10 +1328,8 @@
"type": "SelectControl",
"freeForm": true,
"label": "Number format",
"default": [
".3s",
".3s | 12.3k"
],
"renderTrigger": true,
"default": ".3s",
"choices": [
[
".3s",
Expand Down
3 changes: 2 additions & 1 deletion superset/assets/javascripts/explorev2/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ export const controls = {
type: 'SelectControl',
freeForm: true,
label: 'Number format',
default: D3_TIME_FORMAT_OPTIONS[0],
renderTrigger: true,
default: '.3s',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if use 'D3_TIME_FORMAT_OPTIONS[0]', Number format field is blank in the UI somehow.

choices: D3_TIME_FORMAT_OPTIONS,
description: D3_FORMAT_DOCS,
},
Expand Down
1 change: 1 addition & 0 deletions superset/assets/javascripts/explorev2/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ const visTypes = {
controlSetRows: [
['groupby', 'columns'],
['metrics', 'pandas_aggfunc'],
['number_format'],
],
},
],
Expand Down
9 changes: 9 additions & 0 deletions superset/assets/visualizations/pivot_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ module.exports = function (slice, payload) {
const container = slice.container;
const fd = slice.formData;
const height = container.height();
const numberFormat = fd.number_format;

// payload data is a string of html with a single table element
container.html(payload.data);

// format number
$('td').each(function () {
const tdText = $(this)[0].textContent;
if (!isNaN(tdText) && tdText !== '') {
$(this)[0].textContent = d3.format(numberFormat)(tdText);
}
});

if (fd.groupby.length === 1) {
// When there is only 1 group by column,
// we use the DataTable plugin to make the header fixed.
Expand Down