Skip to content

Commit

Permalink
Make the headers of tables and pivot tables fixed (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
x4base authored and mistercrunch committed Jun 22, 2016
1 parent 8ebe074 commit ab71ee4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
12 changes: 11 additions & 1 deletion caravel/assets/javascripts/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,18 @@ var toggleCheckbox = function (apiUrlPrefix, selector) {
});
};

/**
* Fix the height of the table body of a DataTable with scrollY set
*/
var fixDataTableBodyHeight = function ($tableDom, height) {
var headHeight = $tableDom.find('.dataTables_scrollHead').height();
$tableDom.find('.dataTables_scrollBody')
.css('max-height', height - headHeight);
};

module.exports = {
wrapSvgText: wrapSvgText,
showModal: showModal,
toggleCheckbox: toggleCheckbox
toggleCheckbox: toggleCheckbox,
fixDataTableBodyHeight: fixDataTableBodyHeight
};
9 changes: 8 additions & 1 deletion caravel/assets/visualizations/pivot_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var jQuery = window.jQuery = $;
require('datatables.net-bs');
require('./pivot_table.css');
require('../node_modules/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
var utils = require('../javascripts/modules/utils');

module.exports = function (slice) {
var container = slice.container;
Expand All @@ -13,12 +14,18 @@ module.exports = function (slice) {
var form_data = json.form_data;
container.html(json.data);
if (form_data.groupby.length === 1) {
var height = container.height();
var table = container.find('table').DataTable({
paging: false,
searching: false,
bInfo: false
bInfo: false,
scrollY: height + "px",
scrollCollapse: true,
scrollX: true
});
table.column('-1').order('desc').draw();
utils.fixDataTableBodyHeight(
container.find('.dataTables_wrapper'), height);
}
slice.done(json);
}).fail(function (xhr) {
Expand Down
9 changes: 8 additions & 1 deletion caravel/assets/visualizations/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var px = window.px || require('../javascripts/modules/caravel.js');
require('./table.css');
require('datatables.net-bs');
require('../node_modules/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
var utils = require('../javascripts/modules/utils');

function tableVis(slice) {
var f = d3.format('.3s');
Expand Down Expand Up @@ -115,11 +116,17 @@ function tableVis(slice) {
return d.val;
}
});
var height = slice.container.height();
var datatable = slice.container.find('.dataTable').DataTable({
paging: false,
searching: form_data.include_search,
bInfo: false
bInfo: false,
scrollY: height + "px",
scrollCollapse: true,
scrollX: true
});
utils.fixDataTableBodyHeight(
slice.container.find('.dataTables_wrapper'), height);
// Sorting table by main column
if (form_data.metrics.length > 0) {
var main_metric = form_data.metrics[0];
Expand Down

0 comments on commit ab71ee4

Please sign in to comment.