Skip to content

Rolling Table

Star

TuiRollingTable is a scrolling table component specifically designed for data visualization dashboards. Built on the TuiRolling engine, it supports fixed headers, seamless content scrolling, leaderboard highlighting, and highly customizable cell rendering. It supports both pure data-driven rendering and the embedding of charts, buttons, or images via slots.

Basic Usage

Basic Data Rendering

The simplest usage is to define the table header using header and pass a data array into TuiRollingTableRow.

  • header: An array of table header titles.
  • visibleLength: The number of rows displayed in the visible area.
html
<script setup>
import { ref } from 'vue';

const tableHeader = ['Rank', 'Region', 'Sales', 'Ratio'];
const tableData = ref([
  [1, 'Beijing', '12,420', '30%'],
  [2, 'Shanghai', '10,230', '25%'],
  [3, 'Guangzhou', '8,100', '20%'],
  [4, 'Shenzhen', '6,540', '15%'],
  [5, 'Chengdu', '4,320', '10%']
]);
</script>

<template>
  <div style="height: 300px">
    <TuiRollingTable 
      :header="tableHeader" 
      :visibleLength="4" 
      autoRolling
    >
      <TuiRollingTableRow 
        v-for="(row, index) in tableData" 
        :key="index" 
        :index="index" 
        :data="row"
      />
    </TuiRollingTable>
  </div>
</template>

Column Configuration

The component provides a series of properties to finely control column performance.

  • columnWidths: Defines an array of column widths. Supports numbers (px) or null (auto-expand).
  • columnAligns: Defines an array of alignment methods ('start', 'center', 'end').
  • hasIndexCol: Whether to automatically add a serial number to the first column.
  • showRankings: Whether to enable highlighting for the top three items (requires hasIndexCol to be enabled).
html
<TuiRollingTable 
  :header="['Name', 'Type', 'Status', 'Time']"
  :columnWidths="[null, 100, 80, 150]"
  :columnAligns="['start', 'center', 'center', 'end']"
  hasIndexCol
  showRankings
>
  ...
</TuiRollingTable>

Appearance and Style

TuiRollingTable supports deep customization of appearance through Props or CSS Variables to adapt to different dashboard themes.

Via Props

Set colors directly through attributes:

  • headerBG / headerFC: Background and text color of the header.
  • oddRowBG / evenRowBG: Background colors for odd and even rows (to achieve zebra striping).
  • rowBD: Row border color.
html
<TuiRollingTable 
  headerBG="#1a3c6e"
  headerFC="#00ffff"
  oddRowBG="rgba(0, 255, 255, 0.05)"
  rowBD="rgba(0, 255, 255, 0.2)"
>
  ...
</TuiRollingTable>

Via CSS Variables

Define variables in the parent container to achieve more complex style control (such as gradients).

css
.my-custom-table {
  --tui-rolltb-head-bg: linear-gradient(90deg, #00c6ff, #0072ff);
  --tui-rolltb-head-fc: #fff;
  --tui-rolltb-head-lh: 50px; /* Header height */
  --tui-rolltb-col-fc: #eee;  /* Cell text color */
}

Advanced Column Types

Through the columnTypes attribute, you can define special column types, such as percentage progress bars or operation bars.

Progress Bar Column (Percent)

Set the corresponding column type to 'percent' and configure it with progressConfig.

html
<TuiRollingTable 
  :header="['Project', 'Progress']"
  :columnTypes="[null, 'percent']"
  :progressConfig="{
    unit: 'k Tons',
    strokeWidth: 12,
    thresholds: { warning: 50, success: 80 }
  }"
>
  ...
</TuiRollingTable>

Operation Bar Column (Operation)

Set the type to 'operation' and define buttons via the operation attribute. Listen to the @operation event to handle clicks.

html
<script setup>
const ops = [
  { label: "View", value: "view", type: "primary" },
  { label: "Delete", value: "del", type: "danger" }
];
const handleOp = ({ index, row, value }) => {
  console.log('Clicked:', value, 'Row Data:', row);
};
</script>

<template>
  <TuiRollingTable 
    :header="['Name', 'Operation']"
    :columnTypes="[null, 'operation']"
    :operation="ops"
    @operation="handleOp"
  >
    ...
  </TuiRollingTable>
</template>

Slot Customization

For more complex content (such as placing images, tags, or custom components in cells), use TuiRollingTableCol with slots.

Note

When using the slot mode, TuiRollingTableRow does not need the data attribute; instead, write TuiRollingTableCol directly inside it.

html
<template>
  <TuiRollingTable :header="['Status', 'Details', 'Operation']">
    <TuiRollingTableRow 
      v-for="(item, index) in list" 
      :key="index" 
      :index="index"
    >
      <TuiRollingTableCol>
        <TuiTag :type="item.status === 'ok' ? 'success' : 'danger'">
          {{ item.status }}
        </TuiTag>
      </TuiRollingTableCol>
      
      <TuiRollingTableCol>{{ item.detail }}</TuiRollingTableCol>
      
      <TuiRollingTableCol>
        <TuiButton size="small" plain @click="doSomething(item)">Audit</TuiButton>
      </TuiRollingTableCol>
    </TuiRollingTableRow>
  </TuiRollingTable>
</template>

API Reference

TuiRollingTable Props

PropertyTypeDefaultDescription
visibleLengthNumber5Core. Number of rows displayed in the visible area.
headerArray[]Array of table header titles.
columnWidthsArray[]Array of column widths (px/null).
columnAlignsArray[]Array of column alignments (start, center, end).
columnTypesArray[]Array of column types (string, percent, operation).
operationArray[]Array of configuration objects for the operation bar.
hasIndexColBooleanfalseWhether to display the serial number column.
showRankings
V0.0.6+
BooleanfalseWhether to enable highlighting for the top three ranks.
headerBGString-Header background color.
oddRowBGString-Odd row background color.
evenRowBGString-Even row background color.
rowBDString-Row border color.
fontColorString-Global text color.
theadHeightNumber-Header height (px).
intervalNumber3000Scrolling interval.
modeString'item'Scrolling mode (item, page).
seamlessBooleantrueWhether scrolling is seamless.
fillDataBooleanfalseWhether to fill data if insufficient.
progressConfigObject-Configuration for progress bar columns.
resizeObserverString'global'Size monitoring strategy.

TuiRollingTableCol Props

PropertyTypeDefaultDescription
contentTypeStringnullContent type hint (component, etc.) used for special style corrections.

TuiRollingTableRow Props

PropertyTypeDefaultDescription
indexNumberRequiredRow index.
dataArraynullRow data (used in pure data mode).

Emits

Event NameDescriptionCallback Parameters
operationTriggered when an operation bar button is clicked.{ index, row, value, label }
startTriggered when scrolling starts.-
rollingTriggered during scrolling.(offset)

Credits

This component was inspired by the scrollBoard component in the @jiaminghi/data-view library. Having used that component heavily in earlier projects, the developer felt its functionality could be expanded, leading to this new implementation based on the TuiRolling component within the TechUI library.

Released under the MIT License.