Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(convert-manager): return rowdata as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
VMBindraban committed May 12, 2017
1 parent ca33154 commit 550ab75
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/usage.md
Expand Up @@ -84,6 +84,8 @@ This is used for table content, but also the table headers. There's support for
#### valueConverters
You can give every colum one or more `valueConverter`s (`|` seperated). You need to define the converters in your `main.js` as a global resource. *[More information](http://eisenbergeffect.bluespire.com/binding-with-value-converters-in-aurelia/)()

Note: In the `toView()` of the valueConverter there is a 3rd parameter that includes the data of the row. This can be useful if you want to convert something based on a other column. For example price and currency.

Example:

```js
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/datatable.html
Expand Up @@ -61,8 +61,8 @@

<!-- Columns -->
<td repeat.for="columnLabel of columnLabels">
<span if.bind="!columnLabel.route && !route && !select" innerhtml.bind="displayValue(row, columnLabel.column) | convertManager: columnLabel.converter"></span>
<a if.bind="route || select || columnLabel.route" click.delegate="selected(row, columnLabel)" innerhtml.bind="displayValue(row, columnLabel.column) | convertManager: columnLabel.converter"></a>
<span if.bind="!columnLabel.route && !route && !select" innerhtml.bind="displayValue(row, columnLabel.column) | convertManager: columnLabel.converter : row"></span>
<a if.bind="route || select || columnLabel.route" click.delegate="selected(row, columnLabel)" innerhtml.bind="displayValue(row, columnLabel.column) | convertManager: columnLabel.converter : row"></a>
</td>

<!-- Actions -->
Expand Down
10 changes: 5 additions & 5 deletions src/convert-manager.js
Expand Up @@ -10,19 +10,19 @@ export class ConvertManagerValueConverter {
this.logger = getLogger('aurelia-datatable');
}

runConverter(value, converter, convertParams) {
runConverter(value, converter, convertParams, rowData) {
let valueConverter = this.viewResources.getValueConverter(converter);

if (valueConverter) {
return valueConverter.toView(value, convertParams);
return valueConverter.toView(value, convertParams, rowData);
}

this.logger.error('No ValueConverter named "' + converter + '" was found!');

return value;
}

toView(value, converters) {
toView(value, converters, rowData) {
if (!converters) {
return value;
}
Expand All @@ -35,15 +35,15 @@ export class ConvertManagerValueConverter {
let index = converter.indexOf(':');

if (index < 0) {
value = this.runConverter(value, converter);
value = this.runConverter(value, converter, null, rowData);

continue;
}

let name = converter.slice(0, index);
let param = this.parseParams(converter.slice(index + 1).trim());

value = this.runConverter(value, name, param);
value = this.runConverter(value, name, param, rowData);
}

return value;
Expand Down

0 comments on commit 550ab75

Please sign in to comment.