Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/oui-datagrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ Or you can use the `page-size` property. It takes precedence over value configur
</oui-datagrid>
```

### Access row index

```html:preview
<oui-datagrid rows="$ctrl.data" page-size="5">
<oui-column title="'Index'">
{{$rowIndex}}
</oui-column>
<oui-column title="'Name'">
{{$row.firstName}} {{$row.lastName}}
</oui-column>
<oui-column property="email">
<a href="mailto:{{$value}}">{{$value}}</a>
</oui-column>
<oui-column property="phone"></oui-column>
<oui-column property="birth">
{{$value | date:shortDate}}
</oui-column>
</oui-datagrid>
```

### Remote data

```html
Expand Down
1 change: 1 addition & 0 deletions packages/oui-datagrid/src/cell/cell.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class {
this.cellScope.$row = this.row;
this.cellScope.$column = this.column;
this.cellScope.$value = this.row[this.column.name];
this.cellScope.$rowIndex = this.index;

if (this.column.compiledTemplate) {
this.column.compiledTemplate(this.cellScope, clone => {
Expand Down
32 changes: 32 additions & 0 deletions packages/oui-datagrid/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,38 @@ describe("ouiDatagrid", () => {
expect(actualCellHtml).toBe(`test: ${fakeData[0].lastName}`);
});

it("should support row index data binding inside cell", () => {
const element = TestUtils.compileTemplate(`
<oui-datagrid rows="$ctrl.rows">
<oui-column property="firstName"></oui-column>
<oui-column property="">
test: {{ $rowIndex }}
</oui-column>
</oui-datagrid>
`, {
rows: fakeData.slice(0, 5)
}
);

const $firstRow = getRow(element, 0);
expect(
getCell($firstRow, 1).children().children().html()
.trim())
.toBe("test: 0");

const $middleRow = getRow(element, 2);
expect(
getCell($middleRow, 1).children().children().html()
.trim())
.toBe("test: 2");

const $lastRow = getRow(element, 4);
expect(
getCell($lastRow, 1).children().children().html()
.trim())
.toBe("test: 4");
});

it("should support parent binding inside cell", () => {
const element = TestUtils.compileTemplate(`
<oui-datagrid rows="$ctrl.rows">
Expand Down