Skip to content

Commit

Permalink
docs: add documentation on customizing row selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Nys committed Jul 8, 2024
1 parent 4321540 commit dac69c3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{! BEGIN-SNIPPET docs-example-customizing-row-selection.hbs }}
<EmberTable as |t|>
<t.head @columns={{this.columns}} />

<t.body
@rows={{this.rows}}
@onSelect={{action this.selectRows}}
@selection={{this.selection}}
as |b|
>
<b.row as |r|>
<r.cell>
<:select as |rowMeta onSelectionToggled|>
<YourCustomCheckboxComponent
@checked={{rowMeta.isGroupSelected}}
@onClick={{onSelectionToggled}}
/>
</:select>
<:default as |value|>
{{value}}
</:default>
</r.cell>
</b.row>
</t.body>
</EmberTable>
{{! END-SNIPPET }}
10 changes: 9 additions & 1 deletion tests/dummy/app/templates/docs/guides/body/row-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ itself.
{{demo.snippet label='component.js' name='docs-example-selection-modes.js'}}
{{/docs-demo}}

## Customizing Row Selection

By default, Ember Table renders an input of type `checkbox` alongside an empty `span` element that can be styled to look like a checkbox. If you want to customize the checkbox however, you can pass a named block `:select` to the `EmberTd` component. This block will receive `rowMeta` and the `onSelectionToggled` action as yielded arguments:

{{#docs-demo as |demo|}}
{{demo.snippet name='docs-example-customizing-row-selection.hbs'}}
{{/docs-demo}}

## Aborting a Selection

Row selection follows a <a href="https://embermap.com/topics/component-side-effects/data-down-actions-up">DDAU</a> pattern, whereby the `onSelect` action handler supplied to Ember Table has control over which rows become selected. To ignore a user selection, it suffices to simply do nothing in the action handler.
Expand All @@ -92,4 +100,4 @@ To reset all internal state relating to an attempted user selection, call the `a
{{#docs-demo as |demo|}}
{{demo.snippet name='docs-example-aborting-a-selection.hbs'}}
{{demo.snippet label='component.js' name='docs-example-aborting-a-selection.js'}}
{{/docs-demo}}
{{/docs-demo}}

0 comments on commit dac69c3

Please sign in to comment.