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

Create plugin: row grouping #20

Open
NullVoxPopuli opened this issue Oct 16, 2022 · 0 comments
Open

Create plugin: row grouping #20

NullVoxPopuli opened this issue Oct 16, 2022 · 0 comments

Comments

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Oct 16, 2022

This plugin would provide an alternate API that consumers would use to enumerate their rows. Potentially something like:

type Rows = Array<
  | Row 
  | { 
      groupName: string,
      ...otherProperties,
      rows: Row[]
    }
>;

To access these groups, a consumer would need to do something like:

import { meta } from 'ember-headless-table/plugins';
// ...
meta.forTable(table, RowGrouping).rows;

This could be abstracted away from consumers via a helper function:

export const groupedRows = (table) => meta.forTable(table, RowGrouping).rows;
export const isGroup = (row: Row | RowGroup) => 'groupName' in row;

Which could then be used in a template like this:

import { groupedRows, isGroup } from '...';

<template>
  {{! ... }}
  {{#each (groupedRows table) as |row|}}
    {{#if (isGroup row)}}
      markup tbd

         {{#each row.rows as |row|}}
             group content here
         {{/each}}

    {{else}}
      <tr>
          normal rows
      </tr>
    {{/if}}
  {{/each}}
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant