Table

yarn add @freshworks/table

Simple Usage of Table

In the simplest form, nucleus-table takes in the rows and columns and presents it as a table

Source Contact Status
Twitter Albus D
WhatsApp Percival D
FB Wulfric D
Call Brian D
Email Dumbledore D
FB Gandalf D
Twitter Severus D
Call Alan D
ABC Snape D
{{#nucleus-table
  columns=columns
  rows=rows
  as |table|
}}
{{table.table}}
{{/nucleus-table}}

Customising the Table

1. Basic Customisation Attributes

We can specify the number of rows per page with the pageSize property and also change the main paginator to a mini paginator with the isMini property. We can also disable the filter mechanism with the canFilter property

Source Contact Status
ABC Rick D
Twitter Sanchez D
{{#nucleus-table
  columns=columns
  rows=rows
  pageSize=2
  canFilter=false
  isMini=true
  as |table|}}
  {{table.table}}
{{/nucleus-table}}

2. Selection of all Rows

The selectAll prop can be used to select all entries displayed on the table currently

Click on the checbox to toggle selection of all rows
Source Contact PhNo
FB Gandalf 913
Twitter Severus 915
Call Alan 916
ABC Snape 917
WhatsApp Wheeler 918
ABC Joyce 919
Email Byers 920
FB El - Eleven 921
{{input type="checkbox" checked=selectAll onClick=(action 'allSelect')}}
Click on the checbox to toggle selection of all rows
  {{#nucleus-table
    columns=columns
    rows=rows
    selectAll=selectAll
    as |table|}}
    {{table.table}}
  {{/nucleus-table}}

Advanced Usage

Nucleus Table provides attributes and contextual components to deal with many real-world usecases

1. Using custom table cell components

We can use custom components for the cells by accessing the table cell's contextual component. It exposes the cell's value as value and also the current column and row as column and row attribute respectively.

Source Contact PhNo
ABC Rick 914
Twitter Sanchez 914
Email Jim 914
FB Hopper 914
Call Nancy 914
WhatsApp Wheeler 914
ABC Joyce 914
Email Byers 914
FB El - Eleven 914
{{#nucleus-table
  columns=columns
  rows=rows
  pageSize=9
  as |table|}}
  {{#table.table as |value column row|}}
  {{#if (eq column.name "PhNo")}}
    <a style="text-decoration:underline" href="">{{value}}</a>
  {{else}}
    {{value}}
  {{/if}}
  {{/table.table}}
{{/nucleus-table}}

2. Using a contextual Pagination Component

There are times when we want to specify an extra paginator for the table at a location of our choice. The contextual Pagination component gives the ability to use a paginator at any location like within a toolbar.

Source Contact Status
ABC Rick D
Twitter Sanchez D
Email Jim D
FB Hopper D
Call Nancy D
WhatsApp Wheeler D
ABC Joyce D
Email Byers D
FB El - Eleven D
{{#nucleus-table
  columns=columns
  rows=rows
  as |table|}}
  <div style="display:flex; align-items: baseline; background-color: white;">
    {{nucleus-button label="Delete" variant="secondary"}}
    {{table.paginator mini=true}}
  </div>
  {{table.table}}
{{/nucleus-table}}

3. Using the Selected Rows

The selected rows can be accessed using the selectedRows attribute as shown below.

Selected Contacts are:
Source Contact Status
ABC Rick D
Twitter Sanchez D
Email Jim D
FB Hopper D
Call Nancy D
WhatsApp Wheeler D
ABC Joyce D
Email Byers D
FB El - Eleven D
{{#nucleus-table
  columns=columns
  rows=rows
  as |table|}}
  Selected Contacts are: 
  {{#each table.selectedRows as |entry|}}
    {{entry.contact}}
  {{/each}}
  {{table.table}}
{{/nucleus-table}}

Accessibility

  1. Use the tableCaption attribute to the table to give an overview about the table's contents

    {{#nucleus-table
     columns=columns
     rows=rows
     tableCaption="Contact Details"
     as |table|
    }}
     {{table.table}}
    {{/nucleus-table}}
  2. If you are using custom components inside the cell, ensure that the component is appropriately accessible

Guidelines

Do's

  1. Ensure that the esssential columns cannot be filtered

  2. If an interactive cell element is present, the user must be given cues for understanding.

🚫Dont's

  1. Do not clutter the table with many columns