-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update slickgrid module( add bsdropdown service and formatter)
- Loading branch information
1 parent
ef7802a
commit 37d1561
Showing
10 changed files
with
92 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
41 changes: 41 additions & 0 deletions
41
src/app/modules/angular-slickgrid/formatters/__tests__/bsDropdownFormatter.spec.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Column } from '../../models'; | ||
import { bsDropdownFormatter } from '../bsDropdownFormatter'; | ||
|
||
describe('the Bootstrap dropdown Formatter', () => { | ||
it('should throw an error when omitting to pass "propertyNames" to "params"', () => { | ||
expect(() => bsDropdownFormatter(0, 0, 'anything', {} as Column, {})) | ||
.toThrowError('You must provide the "label" or "formatterLabel" via the generic "params"'); | ||
}); | ||
|
||
it('should always return a dropdown template with the label provided in the "label" property from "params"', () => { | ||
const input = null; | ||
const label = 'Action'; | ||
const row = 0; | ||
const cell = 0; | ||
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {}); | ||
|
||
expect(result).toBe(`<div id="myDrop-r${row}-c${cell}" class="dropdown"> | ||
<a class="dropdown-toggle"> | ||
${label} | ||
<span class="caret"></span> | ||
</a> | ||
</div>`); | ||
|
||
}); | ||
|
||
it('should always return a a dropdown template with the label provided in the "formatterLabel" property from "params"', () => { | ||
const input = null; | ||
const label = 'Action'; | ||
const row = 0; | ||
const cell = 0; | ||
const result = bsDropdownFormatter(row, cell, input, { field: 'user', params: { label } } as Column, {}); | ||
|
||
expect(result).toBe(`<div id="myDrop-r${row}-c${cell}" class="dropdown"> | ||
<a class="dropdown-toggle"> | ||
${label} | ||
<span class="caret"></span> | ||
</a> | ||
</div>`); | ||
|
||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/app/modules/angular-slickgrid/formatters/bsDropdownFormatter.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Column } from './../models/column.interface'; | ||
import { Formatter } from './../models/formatter.interface'; | ||
|
||
export const bsDropdownFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => { | ||
const columnParams = columnDef && columnDef.params || {}; | ||
const label = columnParams.label || columnParams.formatterLabel; | ||
|
||
if (!label) { | ||
throw new Error(`You must provide the "label" or "formatterLabel" via the generic "params" options (e.g.: { formatter: Formatters.bsDropdown, params: { formatterLabel: 'Label' }}`); | ||
} | ||
|
||
return `<div id="myDrop-r${row}-c${cell}" class="dropdown"> | ||
<a class="dropdown-toggle"> | ||
${label} | ||
<span class="caret"></span> | ||
</a> | ||
</div>`; | ||
}; |
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
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
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
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
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