Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Commit b84e08e

Browse files
marie-jAxelPeter
authored andcommitted
feat(oui-datagrid): permit to access row index (#296)
1 parent 3cf97fc commit b84e08e

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

packages/oui-datagrid/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@ Or you can use the `page-size` property. It takes precedence over value configur
294294
</oui-datagrid>
295295
```
296296

297+
### Access row index
298+
299+
```html:preview
300+
<oui-datagrid rows="$ctrl.data" page-size="5">
301+
<oui-column title="'Index'">
302+
{{$rowIndex}}
303+
</oui-column>
304+
<oui-column title="'Name'">
305+
{{$row.firstName}} {{$row.lastName}}
306+
</oui-column>
307+
<oui-column property="email">
308+
<a href="mailto:{{$value}}">{{$value}}</a>
309+
</oui-column>
310+
<oui-column property="phone"></oui-column>
311+
<oui-column property="birth">
312+
{{$value | date:shortDate}}
313+
</oui-column>
314+
</oui-datagrid>
315+
```
316+
297317
### Remote data
298318

299319
```html

packages/oui-datagrid/src/cell/cell.controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default class {
4040
this.cellScope.$row = this.row;
4141
this.cellScope.$column = this.column;
4242
this.cellScope.$value = this.row[this.column.name];
43+
this.cellScope.$rowIndex = this.index;
4344

4445
if (this.column.compiledTemplate) {
4546
this.column.compiledTemplate(this.cellScope, clone => {

packages/oui-datagrid/src/index.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,38 @@ describe("ouiDatagrid", () => {
10761076
expect(actualCellHtml).toBe(`test: ${fakeData[0].lastName}`);
10771077
});
10781078

1079+
it("should support row index data binding inside cell", () => {
1080+
const element = TestUtils.compileTemplate(`
1081+
<oui-datagrid rows="$ctrl.rows">
1082+
<oui-column property="firstName"></oui-column>
1083+
<oui-column property="">
1084+
test: {{ $rowIndex }}
1085+
</oui-column>
1086+
</oui-datagrid>
1087+
`, {
1088+
rows: fakeData.slice(0, 5)
1089+
}
1090+
);
1091+
1092+
const $firstRow = getRow(element, 0);
1093+
expect(
1094+
getCell($firstRow, 1).children().children().html()
1095+
.trim())
1096+
.toBe("test: 0");
1097+
1098+
const $middleRow = getRow(element, 2);
1099+
expect(
1100+
getCell($middleRow, 1).children().children().html()
1101+
.trim())
1102+
.toBe("test: 2");
1103+
1104+
const $lastRow = getRow(element, 4);
1105+
expect(
1106+
getCell($lastRow, 1).children().children().html()
1107+
.trim())
1108+
.toBe("test: 4");
1109+
});
1110+
10791111
it("should support parent binding inside cell", () => {
10801112
const element = TestUtils.compileTemplate(`
10811113
<oui-datagrid rows="$ctrl.rows">

0 commit comments

Comments
 (0)