superset/caravel/assets/visualizations/pivot_table.js
Maxime Beauchemin a8fd23dfa4 Linting JSX files (#941)
`.jsx` linting is now in-scope for the `npm run lint` command, and
I linted the base files and some of the viz, there's still quite a bit
of work there, but that's a first pass on it.
2016-08-22 13:21:30 -07:00

39 lines
1.1 KiB
JavaScript

import { fixDataTableBodyHeight } from '../javascripts/modules/utils';
const $ = require('jquery');
require('datatables.net-bs');
require('./pivot_table.css');
require('datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
module.exports = function (slice) {
const container = slice.container;
function refresh() {
$.getJSON(slice.jsonEndpoint(), function (json) {
const fd = json.form_data;
container.html(json.data);
if (fd.groupby.length === 1) {
const height = container.height();
const table = container.find('table').DataTable({
paging: false,
searching: false,
bInfo: false,
scrollY: height + 'px',
scrollCollapse: true,
scrollX: true,
});
table.column('-1').order('desc').draw();
fixDataTableBodyHeight(
container.find('.dataTables_wrapper'), height);
}
slice.done(json);
}).fail(function (xhr) {
slice.error(xhr.responseText, xhr);
});
}
return {
render: refresh,
resize: refresh,
};
};