2016-08-22 16:21:30 -04:00
|
|
|
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');
|
2016-08-22 16:21:30 -04:00
|
|
|
require('datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
|
2016-03-18 02:44:58 -04:00
|
|
|
|
|
|
|
module.exports = function (slice) {
|
2016-08-22 16:21:30 -04:00
|
|
|
const container = slice.container;
|
2016-03-18 02:44:58 -04:00
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
$.getJSON(slice.jsonEndpoint(), function (json) {
|
2016-08-22 16:21:30 -04:00
|
|
|
const fd = json.form_data;
|
2016-03-18 02:44:58 -04:00
|
|
|
container.html(json.data);
|
2016-08-22 16:21:30 -04:00
|
|
|
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,
|
2016-04-11 15:11:47 -04:00
|
|
|
searching: false,
|
2016-06-22 19:16:27 -04:00
|
|
|
bInfo: false,
|
2016-08-22 16:21:30 -04:00
|
|
|
scrollY: height + 'px',
|
2016-06-22 19:16:27 -04:00
|
|
|
scrollCollapse: true,
|
2016-07-21 00:32:20 -04:00
|
|
|
scrollX: true,
|
2016-03-18 02:44:58 -04:00
|
|
|
});
|
|
|
|
table.column('-1').order('desc').draw();
|
2016-08-22 16:21:30 -04:00
|
|
|
fixDataTableBodyHeight(
|
2016-06-22 19:16:27 -04:00
|
|
|
container.find('.dataTables_wrapper'), height);
|
2016-03-18 02:44:58 -04:00
|
|
|
}
|
|
|
|
slice.done(json);
|
|
|
|
}).fail(function (xhr) {
|
2016-06-21 12:42:44 -04:00
|
|
|
slice.error(xhr.responseText, xhr);
|
2016-03-18 02:44:58 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
render: refresh,
|
2016-07-21 00:32:20 -04:00
|
|
|
resize: refresh,
|
2016-03-18 02:44:58 -04:00
|
|
|
};
|
|
|
|
};
|