Skip to content

Commit

Permalink
fix(formatter): multipleFormatter should pass value to next formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Mar 10, 2018
1 parent cbb01d9 commit bf6b006
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Column, Formatter } from './../models/index';

export const multipleFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => {
export const multipleFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: any) => {
const params = columnDef.params || {};
if (!params.formatters || !Array.isArray(params.formatters)) {
throw new Error(`The multiple formatter requires the "formatters" to be provided as a column params.
For example: this.columnDefinitions = [{ id: title, field: title, formatter: Formatters.multiple, params: { formatters: [Formatters.lowercase, Formatters.uppercase] }`);
}
const formatters: Formatter[] = params.formatters;
let formattedValue = '';

// loop through all Formatters, the value of 1st formatter will be used by 2nd formatter and so on.
// they are piped and executed in sequences
let currentValue = value;
for (const formatter of formatters) {
formattedValue = formatter(row, cell, value, columnDef, dataContext);
currentValue = formatter(row, cell, currentValue, columnDef, dataContext, grid);
}
return formattedValue;
return currentValue;
};

0 comments on commit bf6b006

Please sign in to comment.