Skip to content

Commit

Permalink
port beginSlice, endSlice dataGrid -> dataTable
Browse files Browse the repository at this point in the history
basic pagination support
thanks again @calvino

fixes #101
  • Loading branch information
gordonwoodhull committed Oct 30, 2015
1 parent 65af1f8 commit 14b9208
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
18 changes: 18 additions & 0 deletions spec/data-table-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ describe('dc.dataTable', function () {
});
});

describe('slicing entries', function () {
beforeEach(function () {
chart.beginSlice(1);
chart.redraw();
});

it('slice beginning', function () {
expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(2);
});

it('slice beginning and end', function () {
chart.endSlice(2);
chart.redraw();

expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(1);
});
});

describe('external filter', function () {
beforeEach(function () {
countryDimension.filter('CA');
Expand Down
32 changes: 31 additions & 1 deletion src/data-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ dc.dataTable = function (parent, chartGroup) {
return d;
};
var _order = d3.ascending;
var _beginSlice = 0;
var _endSlice;
var _showGroups = true;

_chart._doRender = function () {
Expand Down Expand Up @@ -155,7 +157,7 @@ dc.dataTable = function (parent, chartGroup) {
.sortKeys(_order)
.entries(entries.sort(function (a, b) {
return _order(_sortBy(a), _sortBy(b));
}));
}).slice(_beginSlice, _endSlice));
}

function renderRows (groups) {
Expand Down Expand Up @@ -202,6 +204,34 @@ dc.dataTable = function (parent, chartGroup) {
return _chart;
};

/**
#### .beginSlice([index])
Get or set the index of the beginning slice which determines which entries get displayed by the widget
Useful when implementing pagination.
**/
_chart.beginSlice = function (_) {
if (!arguments.length) {
return _beginSlice;
}
_beginSlice = _;
return _chart;
};

/**
#### .endSlice([index])
Get or set the index of the end slice which determines which entries get displayed by the widget
Useful when implementing pagination.
**/
_chart.endSlice = function (_) {
if (!arguments.length) {
return _endSlice;
}
_endSlice = _;
return _chart;
};

/**
* Get or set column functions. The data table widget now supports several methods of specifying
* the columns to display. The original method, first shown below, uses an array of functions to
Expand Down

0 comments on commit 14b9208

Please sign in to comment.