1.1.2 • Published 5 years ago

@rei/cdr-data-table v1.1.2

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

CdrDataTable

For the most up-to-date information, see REI Cedar documentation.

Properties

NameTypeDefault
idstringN/A
Sets unique id on <table> element.
NameTypeDefault
colHeadersarray/booleanfalse
The colHeaders prop accepts an array of column header strings or a boolean value. Renders in the thead slot. If the value is false, column heads are not displayed. For example, possible values are: ‘Column Header 1’, ‘Column Header 2’, ...
NameTypeDefault
rowHeadersarray/booleanfalse
The rowHeaders prop accepts an array of row header strings or a boolean value. Renders in the tbody slot. If the value is false, row heads are not displayed. For example, possible values are: ‘Row Header 1’, ‘Row Header 2’, ...
NameTypeDefault
rowDataarray[]
Sets an array of objects representing each row in the table.
NameTypeDefault
keyOrderarray[]
Determines the order of cell content in a row.
NameTypeDefault
captionstringN/A
Sets the caption text for the table

Slots

NameNotes
theadSets the innerHTML for the thead element. Includes default slot content.
tbodySets the innerHTML for the tbody element. Includes default slot content.

Installation

Resources are available within the CdrDataTable package:

  • Component: @rei/cdr-data-table
  • Component styles: cdr-data-table.css

To incorporate the required assets for a component, use the following steps:

1. Install using NPM

Install the CdrDataTable package using npm in your terminal:

Terminal

npm i -S @rei/cdr-data-table

2. Import dependencies

main.js

// import your required CSS.
import "@rei/cdr-data-table/dist/cdr-data-table.css";

3. Add component to a template

local.vue

<template>
  <cdr-table
    id="size-details"
    :col-headers="colHeaders"
    :row-headers="rowHeaders"
    :row-data="rowData"
    :key-order="keyOrder"
  />
</template>

<script>
import { CdrTable } from '@rei/cdr-table';
export default {
  ...
  components: {
     CdrTable  
  }, 
  data() {
    ...
  },
}
</script>

Usage

Using Props

The simplest way to use CdrDataTable is using the props API. The below example shows how:

  • The data props (colHeaders, rowHeaders, rowData) are used
  • keyOrder determines values displayed in each cell. The array order must match the colHeaders or column order
<template>
  <cdr-data-table
    id="props-example"
    :col-headers="colHeaders"
    :row-headers="rowHeaders"
    :row-data="rowData"
    :key-order="keyOrder"
    caption="CdrTable props usage"
  />
</template>

<script>
  ...
  data() {
    colHeaders: ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'],
    rowHeaders: ['Chest', 'Sleeve Length', 'Waist', 'Hip', 'Inseam'],
    keyOrder: ['xs', 's', 'm', 'l', 'xl', 'xxl', 'xxxl'],
    rowData: [
      {
        xs: '31.5 - 33',
        s: '35 - 38',
        m: '38 - 41',
        l: '42 - 45',
        xl: '46 - 49',
        xxl: '50 - 53',
        xxxl: '54-57',
      },
      {
        s: '33',
        m: '34',
        l: '35',
        xl: '35.5',
        xxl: '36',
        xxxl: '36.6',
        xs: 'N/A',
      },
      ...
    ],
  },
}
</script>

Using Slots

The same table can be rendered using the v-for Vue directive and CdrDataTable's named slots:

  • Iterates over the data set by looping through items in an array or object
  • Generates appropriate markup for each named slot

In the below examples, the colHeaders prop is set to true because there are column headers for the data table.

<template>
  <cdr-data-table
    id="slots-example"
    :col-headers="true"
    caption="CdrTable slots usage"
  >
    <template slot="thead">
       <tr>
         <th
           class="empty"
           scope="col"
         />
         <th
           v-for="(header, index) in tableData.colHeaders"
           :key="index"
         >
           {{ header }}
         </th>
       </tr>
     </template>
     <template slot="tbody">
       <tr
         v-for="(row, index) in tableData.rowData"
         :key="'tr_' + index"
       >
         <th
           scope="row"
         >{{ tableData.rowHeaders[index] }}</th>
         <td
           v-for="(key, index) in ['xs', 's', 'm', 'l', 'xl', 'xxl', 'xxxl']"
           :key="index"
         >{{ row[key] }}
         </td>
       </tr>
     </template>
  </cdr-data-table>
</template>

<script>
  ...
  data() {
    ...
 ],
  },
}
</script>

The below example uses:

  • compact and borderless modifiers
  • CdrDataTable's named slots
  • Markup is manual, not data-driven
<cdr-data-table
  modifier="compact borderless"
  caption="Full Manual - Compact & Borderless"
  id="full-manual"
>
  <template slot="tbody">
    <tr>
      <th scope=”row”>Best Use</th>
      <td>Casual</td>
    </tr>
    <tr>
      <th scope=”row”>Fabric</th>
      <td>Cotton canvas</td>
    </tr>
    <tr>
      <th scope=”row”>Lining Fabric</th>
      <td>Polyester microfleece/nylon</td>
    </tr>
    ...
  </template>
</cdr-data-table>

Modifiers

Following variants are available to the cdr-data-table modifier attribute:

compactReduces cell padding
borderlessRemoves cell borders
1.1.2

5 years ago

1.1.2-alpha.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.1.0-alpha.4

5 years ago

1.1.0-alpha.3

5 years ago

1.1.0-alpha.2

5 years ago

1.1.0-alpha.1

5 years ago

1.1.0-alpha.0

5 years ago

1.0.0

6 years ago

0.1.0-alpha.3

6 years ago

0.1.0-alpha.2

6 years ago

0.1.0-alpha.1

6 years ago

0.1.0-alpha.0

6 years ago