Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 2ecb6cf

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
Add extra Formatters
1 parent 2d3847b commit 2ecb6cf

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Formatter } from './../models/formatter.interface';
2+
3+
export const arrayToCsvFormatter: Formatter = (row, cell, value, columnDef, dataContext) => {
4+
if (value && Array.isArray(value)) {
5+
return value.join(', ');
6+
}
7+
return '';
8+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Formatter } from './../models/formatter.interface';
2+
3+
export const hyperlinkFormatter: Formatter = (row, cell, value, columnDef, dataContext) => {
4+
const matchUrl = value.match(/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/, 'i');
5+
if (matchUrl && Array.isArray(matchUrl)) {
6+
return `<a href="${matchUrl[0]}">' + value + '</a>`;
7+
}
8+
return '';
9+
};

src/app/modules/angular-slickgrid/formatters/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Column } from './../models';
22
// import { Group, GroupTotals } from '../core'
33
// import { Item } from '../dataview'
4+
import { arrayToCsvFormatter } from './arrayToCsvFormatter';
45
import { checkboxFormatter } from './checkboxFormatter';
56
import { checkmarkFormatter } from './checkmarkFormatter';
67
import { dateIsoFormatter } from './dateIsoFormatter';
@@ -9,6 +10,7 @@ import { dateTimeUsAmPmFormatter } from './dateTimeUsAmPmFormatter';
910
import { dateTimeUsFormatter } from './dateTimeUsFormatter';
1011
import { dateUsFormatter } from './dateUsFormatter';
1112
import { deleteIconFormatter } from './deleteIconFormatter';
13+
import { hyperlinkFormatter } from './hyperlinkFormatter';
1214
import { editIconFormatter } from './editIconFormatter';
1315
import { percentCompleteFormatter } from './percentCompleteFormatter';
1416
import { percentCompleteBarFormatter } from './percentCompleteBarFormatter';
@@ -24,6 +26,7 @@ export interface GroupTotalsFormatter {
2426
}
2527
*/
2628
export const Formatters = {
29+
arrayToCsv: arrayToCsvFormatter,
2730
checkbox: checkboxFormatter,
2831
checkmark: checkmarkFormatter,
2932
dateIso: dateIsoFormatter,
@@ -34,6 +37,7 @@ export const Formatters = {
3437
dateTimeUsAmPm: dateTimeUsAmPmFormatter,
3538
deleteIcon: deleteIconFormatter,
3639
editIcon: editIconFormatter,
40+
hyperlink: hyperlinkFormatter,
3741
percentComplete: percentCompleteFormatter,
3842
percentCompleteBar: percentCompleteBarFormatter,
3943
progressBar: progressBarFormatter,

0 commit comments

Comments
 (0)