-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from CrowdStrike/document-default-values
Add demo about default values
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
```hbs template | ||
<div class="h-full overflow-auto" {{this.table.modifiers.container}}> | ||
<table> | ||
<thead> | ||
<tr> | ||
{{#each this.table.columns as |column|}} | ||
<th> | ||
{{column.name}} | ||
</th> | ||
{{/each}} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{#each this.table.rows as |row|}} | ||
<tr> | ||
{{#each this.table.columns as |column|}} | ||
<td> | ||
{{column.getValueForRow row}} | ||
</td> | ||
{{/each}} | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> | ||
</div> | ||
``` | ||
|
||
```js component | ||
import Component from '@glimmer/component'; | ||
|
||
import { headlessTable } from 'ember-headless-table'; | ||
import { DATA } from 'docs-app/sample-data'; | ||
|
||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { setComponentTemplate } from '@ember/component'; | ||
|
||
export default class extends Component { | ||
table = headlessTable(this, { | ||
columns: () => [ | ||
{ name: 'Column A', key: 'missing', options: () => ({ defaultValue: '???' }) }, | ||
{ name: 'column B', key: 'B' }, | ||
{ name: 'column C', key: 'alsoMissing' }, | ||
{ name: 'column D', key: 'D' }, | ||
{ name: 'column E', key: 'E' }, | ||
], | ||
data: () => DATA, | ||
}); | ||
} | ||
``` |
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,44 @@ | ||
# Default values | ||
|
||
The default value can be changed in the column config. | ||
|
||
|
||
## Using strict mode | ||
|
||
In strict mode, specifying a default value can be done like this: | ||
```js | ||
import Component from '@glimmer/component'; | ||
import { headlessTable } from 'ember-headless-table'; | ||
|
||
export default class Demo extends Component { | ||
table = headlessTable(this, { | ||
columns: () => [ | ||
{ | ||
name: 'Background color', | ||
key: 'bgColor' | ||
options: () => { | ||
return { | ||
defaultValue: '???', | ||
}; | ||
} | ||
} | ||
/* ... */ | ||
], | ||
/* ... */ | ||
}); | ||
|
||
<template> | ||
{{#each this.table.rows as |row|}} | ||
<tr> | ||
{{#each this.table.columns as |column|}} | ||
|
||
<td> | ||
{{column.getValueForRow row}} | ||
</td> | ||
|
||
{{/each}} | ||
</tr> | ||
{{/each}} | ||
</template> | ||
} | ||
``` |
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