Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass rows count to sub-components #880

Merged
merged 7 commits into from
Mar 18, 2021
Merged

Conversation

ahmacleod
Copy link
Contributor

@ahmacleod ahmacleod commented Mar 15, 2021

Passes the effective row count from each of thead, tbody, tfoot down through the component hierarchy. This count excludes rows that are hidden because their parent is collapsed, reflecting what the user actually sees. It is typically smaller than rows.length.

This can be used in the template to identify when the current row is the bottom rendered row.

Includes docs update and a supporting test.

Example usage:

<EmberTable as |t|>
  <t.head @columns={{columns}} />
  <t.body @rows={{rows}} as |b|>
    <b.row as |r|>
      <r.cell as |cell column row cellMeta columnMeta rowMeta rowsCount|>
        {{#if (eq rowMeta.index 0)}}
          {{!-- custom first row markup --}}
          {{cell}}
        {{else if (lt rowMeta.index (dec rowsCount))}}
          {{!-- middle row markup; `dec` helper is from`ember-composable-helpers` --}}
          {{cell}}
        {{else}}
          {{!-- custom last row markup --}}
          {{cell}}
        {{/if}}
      </r.cell>
    </b.row>
  </t.body>
</EmberTable>

@ahmacleod ahmacleod changed the title Pass row count to row templates Pass rows count to row templates Mar 15, 2021
@mixonic
Copy link
Member

mixonic commented Mar 15, 2021

@ahmacleod can this PR also document the addition?

How do you access the index? Like, can you show an example of the usage?

@ahmacleod
Copy link
Contributor Author

@ahmacleod can this PR also document the addition?

How do you access the index? Like, can you show an example of the usage?

Docs could definitely use a "how to tell which row this is from the template" section. This ties into #879.

Probably best to extend the "Table Meta Data" section, which currently does not even document the existing rowMeta.index property:

https://opensource.addepar.com/ember-table/docs/guides/main/table-meta-data

@ahmacleod ahmacleod marked this pull request as ready for review March 15, 2021 21:08
@ahmacleod ahmacleod changed the title Pass rows count to row templates Pass rows count to sub-components Mar 16, 2021
@ahmacleod ahmacleod requested review from mixonic, a team and jiayingxu March 16, 2021 21:34
@ahmacleod ahmacleod merged commit 8ca59e8 into master Mar 18, 2021
@ahmacleod ahmacleod deleted the alex.macleod.temp/row-count branch March 18, 2021 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants