-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikita Kurguzov
committed
Sep 28, 2018
1 parent
481f19e
commit 266949a
Showing
11 changed files
with
159 additions
and
17 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
17 changes: 17 additions & 0 deletions
17
src/extensions/datatable/DatatableFieldCustomizer.manifest.json
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,17 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-extension-manifest.schema.json", | ||
|
||
"id": "9d86b44c-fc29-424b-8da4-b831b9058e08", | ||
"alias": "DatatableFieldCustomizer", | ||
"componentType": "Extension", | ||
"extensionType": "FieldCustomizer", | ||
|
||
// The "*" signifies that the version should be taken from the package.json | ||
"version": "*", | ||
"manifestVersion": 2, | ||
|
||
// If true, the component can only be installed on sites where Custom Script is allowed. | ||
// Components that allow authors to embed arbitrary script code should set this to true. | ||
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f | ||
"requiresCustomScript": false | ||
} |
15 changes: 15 additions & 0 deletions
15
src/extensions/datatable/DatatableFieldCustomizer.module.scss
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,15 @@ | ||
.Datatable { | ||
.cell { | ||
background-color: "[theme:themePrimary, default:#e5e5e5]"; | ||
display: 'inline-block'; | ||
} | ||
table { | ||
border-collapse: collapse; | ||
width: 100%; | ||
max-width: 100%; | ||
} | ||
td { | ||
padding: .5rem; | ||
border-top: 1px solid #dee2e6; | ||
} | ||
} |
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,64 @@ | ||
import { Log } from '@microsoft/sp-core-library'; | ||
import { override } from '@microsoft/decorators'; | ||
import { | ||
BaseFieldCustomizer, | ||
IFieldCustomizerCellEventParameters | ||
} from '@microsoft/sp-listview-extensibility'; | ||
|
||
import * as strings from 'DatatableFieldCustomizerStrings'; | ||
import styles from './DatatableFieldCustomizer.module.scss'; | ||
|
||
/** | ||
* If your field customizer uses the ClientSideComponentProperties JSON input, | ||
* it will be deserialized into the BaseExtension.properties object. | ||
* You can define an interface to describe it. | ||
*/ | ||
export interface IDatatableFieldCustomizerProperties { | ||
// This is an example; replace with your own property | ||
sampleText?: string; | ||
} | ||
|
||
const LOG_SOURCE: string = 'DatatableFieldCustomizer'; | ||
|
||
export default class DatatableFieldCustomizer | ||
extends BaseFieldCustomizer<IDatatableFieldCustomizerProperties> { | ||
|
||
@override | ||
public onInit(): Promise<void> { | ||
// Add your custom initialization to this method. The framework will wait | ||
// for the returned promise to resolve before firing any BaseFieldCustomizer events. | ||
Log.info(LOG_SOURCE, 'Activated DatatableFieldCustomizer with properties:'); | ||
Log.info(LOG_SOURCE, JSON.stringify(this.properties, undefined, 2)); | ||
Log.info(LOG_SOURCE, `The following string should be equal: "DatatableFieldCustomizer" and "${strings.Title}"`); | ||
return Promise.resolve(); | ||
} | ||
|
||
@override | ||
public onRenderCell(event: IFieldCustomizerCellEventParameters): void { | ||
event.domElement.classList.add(styles.Datatable); | ||
if (event.fieldValue) { | ||
var rows = JSON.parse(event.fieldValue); | ||
var html = '<table class="table"><tbody>'; | ||
for(var i = 0; i < rows.length; i++){ | ||
html += '<tr>'; | ||
var row = rows[i]; | ||
for(var column in row) { | ||
html += '<td>'; | ||
html += row[column]; | ||
html += '</td>'; | ||
} | ||
html += '</tr>'; | ||
} | ||
html += '</tbody></table>'; | ||
event.domElement.innerHTML = html; | ||
} | ||
} | ||
|
||
@override | ||
public onDisposeCell(event: IFieldCustomizerCellEventParameters): void { | ||
// This method should be used to free any resources that were allocated during rendering. | ||
// For example, if your onRenderCell() called ReactDOM.render(), then you should | ||
// call ReactDOM.unmountComponentAtNode() here. | ||
super.onDisposeCell(event); | ||
} | ||
} |
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,5 @@ | ||
define([], function() { | ||
return { | ||
"Title": "DatatableFieldCustomizer" | ||
} | ||
}); |
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,8 @@ | ||
declare interface IDatatableFieldCustomizerStrings { | ||
Title: string; | ||
} | ||
|
||
declare module 'DatatableFieldCustomizerStrings' { | ||
const strings: IDatatableFieldCustomizerStrings; | ||
export = strings; | ||
} |