Skip to content

Commit 0f42926

Browse files
committed
Mark rows as even or odd for styling purposes
1 parent c3ab7f2 commit 0f42926

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

addon/components/ember-tr/component.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default Component.extend({
4848
layout,
4949
tagName: 'tr',
5050
classNames: ['et-tr'],
51-
classNameBindings: ['isSelected', 'isGroupSelected', 'isSelectable'],
51+
classNameBindings: ['isEven:is-even:is-odd', 'isGroupSelected', 'isSelectable', 'isSelected'],
5252

5353
/**
5454
The API object passed in by the table body, header, or footer
@@ -88,6 +88,11 @@ export default Component.extend({
8888

8989
isGroupSelected: readOnly('rowMeta.isGroupSelected'),
9090

91+
isEven: computed('rowMeta.index', function() {
92+
let index = this.rowMeta?.index ?? 0;
93+
return index % 2 === 0;
94+
}),
95+
9196
isSelectable: computed('rowSelectionMode', function() {
9297
let rowSelectionMode = this.get('rowSelectionMode');
9398

tests/integration/components/row-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ let table = new TablePage({
1414
body: {
1515
rows: collection({
1616
isCustomRow: hasClass('custom-row'),
17+
isEven: hasClass('is-even'),
18+
isOdd: hasClass('is-odd'),
1719
}),
1820
},
1921
});
@@ -34,6 +36,17 @@ const USE_EMBER_ARRAY_PARAMETERS = {
3436

3537
module('Integration | row', function() {
3638
parameterizedComponentModule('basic', USE_EMBER_ARRAY_PARAMETERS, function() {
39+
test('marks rows as even or odd', async function(assert) {
40+
await generateTable(this);
41+
42+
assert.true(table.rows.objectAt(0).isEven, 'First row is even');
43+
assert.true(table.rows.objectAt(1).isOdd, 'Second row is odd');
44+
assert.true(table.rows.objectAt(2).isEven, 'Third row is even');
45+
assert.true(table.rows.objectAt(3).isOdd, 'Fourth row is odd');
46+
assert.true(table.rows.objectAt(4).isEven, 'Fifth row is even');
47+
assert.true(table.rows.objectAt(5).isOdd, 'Sixth row is odd');
48+
});
49+
3750
test('can use a custom row component', async function(assert) {
3851
await generateTable(this, {
3952
rowComponent: 'custom-row',

0 commit comments

Comments
 (0)