DEV Community

方帅
方帅

Posted on

How to implement dimension drill-down function when using VTable pivot table component?

Problem Description

Does the VTable pivot table support drill-down interaction on the front end?

Solution

Image description

Configuring this will give you an icon and listen for events (https://visactor.io/vtable/api/events#DRILLMENU_CLICK). Call the interface updateOption to update the full configuration after obtaining new data.

Code Example

You can refer to the official demo: https://visactor.io/vtable/demo/data-analysis/pivot-analysis-table-drill.
Key configuration for drillDown:

const option = {
  records: data,
  rows: [
    {
      dimensionKey: 'Category',
      title: 'Category',
      drillDown: true,
      headerStyle: {
        textStick: true
      },
      width: 'auto'
    }
  ],
  columns: [
    {
      dimensionKey: 'Region',
      title: 'Region',
      headerStyle: {
        textStick: true
      },
      width: 'auto'
    }
  ],
  indicators: ...
};
Enter fullscreen mode Exit fullscreen mode

After configuration, the drill-down icon is displayed, and the click event of the icon drillmenu_click is listened. In the event processing logic, updateOption is called to update the configuration, and the configured drill-down icon changes to the drill-up icon drillUp.

tableInstance.on('drillmenu_click', args => {
  if (args.drillDown) {
    if (args.dimensionKey === 'Category') {
      tableInstance.updateOption({
        records: newData,
        rows: [
          {
            dimensionKey: 'Category',
            title: 'Category',
            drillUp: true,
            headerStyle: {
              textStick: true
            },
            width: 'auto'
          },
          {
            dimensionKey: 'Sub-Category',
            title: 'Sub-Catogery',
            headerStyle: {
              textStick: true
            },
            width: 'auto'
          }
        ],
        columns: ...,
        indicators: ...
      });
    }
  }
Enter fullscreen mode Exit fullscreen mode

Result Display

Here is the official website example effect:

Image description

related resources:

Tutorial on using drill-down and drill-through in pivot tables: https://visactor.io/vtable/guide/data_analysis/pivot_table_dataAnalysis
Demo of using Drill Down and Drill Through in pivot tables: https://visactor.io/vtable/demo/data-analysis/pivot-analysis-table-drill?open_in_browser=true
Related APIs: https://visactor.io/vtable/option/PivotTable-columns-text#drillDown
https://visactor.io/vtable/api/events?open_in_browser=true#DRILLMENU_CLICK
github:https://github.com/VisActor/VTable

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay