Skip to content

Commit 14b9208

Browse files
port beginSlice, endSlice dataGrid -> dataTable
basic pagination support thanks again @calvino fixes #101
1 parent 65af1f8 commit 14b9208

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

spec/data-table-spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ describe('dc.dataTable', function () {
7575
});
7676
});
7777

78+
describe('slicing entries', function () {
79+
beforeEach(function () {
80+
chart.beginSlice(1);
81+
chart.redraw();
82+
});
83+
84+
it('slice beginning', function () {
85+
expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(2);
86+
});
87+
88+
it('slice beginning and end', function () {
89+
chart.endSlice(2);
90+
chart.redraw();
91+
92+
expect(chart.selectAll('tr.dc-table-row')[0].length).toEqual(1);
93+
});
94+
});
95+
7896
describe('external filter', function () {
7997
beforeEach(function () {
8098
countryDimension.filter('CA');

src/data-table.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ dc.dataTable = function (parent, chartGroup) {
3434
return d;
3535
};
3636
var _order = d3.ascending;
37+
var _beginSlice = 0;
38+
var _endSlice;
3739
var _showGroups = true;
3840

3941
_chart._doRender = function () {
@@ -155,7 +157,7 @@ dc.dataTable = function (parent, chartGroup) {
155157
.sortKeys(_order)
156158
.entries(entries.sort(function (a, b) {
157159
return _order(_sortBy(a), _sortBy(b));
158-
}));
160+
}).slice(_beginSlice, _endSlice));
159161
}
160162

161163
function renderRows (groups) {
@@ -202,6 +204,34 @@ dc.dataTable = function (parent, chartGroup) {
202204
return _chart;
203205
};
204206

207+
/**
208+
#### .beginSlice([index])
209+
Get or set the index of the beginning slice which determines which entries get displayed by the widget
210+
Useful when implementing pagination.
211+
212+
**/
213+
_chart.beginSlice = function (_) {
214+
if (!arguments.length) {
215+
return _beginSlice;
216+
}
217+
_beginSlice = _;
218+
return _chart;
219+
};
220+
221+
/**
222+
#### .endSlice([index])
223+
Get or set the index of the end slice which determines which entries get displayed by the widget
224+
Useful when implementing pagination.
225+
226+
**/
227+
_chart.endSlice = function (_) {
228+
if (!arguments.length) {
229+
return _endSlice;
230+
}
231+
_endSlice = _;
232+
return _chart;
233+
};
234+
205235
/**
206236
* Get or set column functions. The data table widget now supports several methods of specifying
207237
* the columns to display. The original method, first shown below, uses an array of functions to

0 commit comments

Comments
 (0)