Permalink
Browse files

feat(convert-manager): return rowdata as argument

  • Loading branch information...
VMBindraban
VMBindraban committed May 12, 2017
1 parent ca33154 commit 550ab75e9152a75152ce61b1bcf7c3336c5a26e6
Showing with 9 additions and 7 deletions.
  1. +2 −0 doc/usage.md
  2. +2 −2 src/bootstrap/datatable.html
  3. +5 −5 src/convert-manager.js
@@ -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
@@ -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 -->
@@ -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;
}
@@ -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;

0 comments on commit 550ab75

Please sign in to comment.