superset/caravel/assets/visualizations/pivot_table.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

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