-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(formatter): multipleFormatter should pass value to next formatter
- Loading branch information
1 parent
cbb01d9
commit bf6b006
Showing
1 changed file
with
7 additions
and
4 deletions.
There are no files selected for viewing
11 changes: 7 additions & 4 deletions
11
aurelia-slickgrid/src/aurelia-slickgrid/formatters/multipleFormatter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |