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

表格单元格内容超出显示如何实现呢? #1801

Closed
DearChen opened this issue May 27, 2024 · 3 comments
Closed

表格单元格内容超出显示如何实现呢? #1801

DearChen opened this issue May 27, 2024 · 3 comments
Assignees

Comments

@DearChen
Copy link

image
第二行黄色的方块我应该怎么实现呢?
我尝试了使用elements.rect去实现,但是我发现超出当前格子的部分被隐藏了。

@DearChen DearChen changed the title 表格内容超出显示如何实现呢? 表格单元格内容超出显示如何实现呢? May 27, 2024
@fangsmile
Copy link
Contributor

应该可以结合合并单元格的能力来实现 @Rui-Sun 可以给个示例

@Rui-Sun
Copy link
Contributor

Rui-Sun commented May 28, 2024

const VGroup = VTable.VGroup;
const VText = VTable.VText;
const VRect = VTable.VRect;
const VTag = VTable.VTag;

const option = {
  container: document.getElementById('container'),
  columns: [
    {
      field: 'bloggerId',
      title: 'bloggerId'
    },
    {
      field: 'bloggerName',
      title: 'bloggerName',
      width: 150
    },
    {
      field: 'fansCount',
      title: 'fansCount',
      fieldFormat(rec) {
        return rec.fansCount + 'w';
      },
      style: {
        fontFamily: 'Arial',
        fontSize: 12,
        fontWeight: 'bold'
      }
    },
    {
      field: 'worksCount',
      title: 'worksCount',
      style: {
        fontFamily: 'Arial',
        fontSize: 12,
        fontWeight: 'bold'
      }
    },
    {
      field: 'viewCount',
      title: 'viewCount',
      fieldFormat(rec) {
        return rec.fansCount + 'w';
      },
      style: {
        fontFamily: 'Arial',
        fontSize: 12,
        fontWeight: 'bold'
      }
    },
    {
      field: 'viewCount',
      title: 'viewCount',
      fieldFormat(rec) {
        return rec.fansCount + 'w';
      },
      style: {
        fontFamily: 'Arial',
        fontSize: 12,
        fontWeight: 'bold'
      }
    },
    {
      field: '',
      title: 'operation',
      width: 100,
      icon: ['favorite', 'message']
    }
  ],
  records: [
    {
      bloggerId: 1,
      bloggerName: 'Virtual Anchor Xiaohua',
      bloggerAvatar: 'https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/custom-render/flower.jpg',
      introduction:
        'Hi everyone, I am Xiaohua, the virtual host. I am a little fairy who likes games, animation and food. I hope to share happy moments with you through live broadcast.',
      fansCount: 400,
      worksCount: 10,
      viewCount: 5,
      city: 'Dream City',
      tags: ['game', 'anime', 'food']
    },
    {
      bloggerId: 2,
      bloggerName: 'Virtual anchor little wolf',
      bloggerAvatar: 'https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/custom-render/wolf.jpg',
      introduction:
        'Hello everyone, I am the virtual anchor Little Wolf. I like music, travel and photography, and I hope to explore the beauty of the world with you through live broadcast.',
      fansCount: 800,
      worksCount: 20,
      viewCount: 15,
      city: 'City of Music',
      tags: ['music', 'travel', 'photography']
    },
    {
      bloggerId: 3,
      bloggerName: 'Virtual anchor bunny',
      bloggerAvatar: 'https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/custom-render/rabbit.jpg',
      introduction:
        'Hello everyone, I am the virtual anchor Xiaotu. I like painting, handicrafts and beauty makeup. I hope to share creativity and fashion with you through live broadcast.',
      fansCount: 600,
      worksCount: 15,
      viewCount: 10,
      city: 'City of Art',
      tags: ['painting', 'handmade', 'beauty makeup']
    },
    {
      bloggerId: 4,
      bloggerName: 'Virtual anchor kitten',
      bloggerAvatar: 'https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/custom-render/cat.jpg',
      introduction:
        'Hello everyone, I am the virtual host Kitty. I am a lazy cat who likes dancing, fitness and cooking. I hope to live a healthy and happy life with everyone through the live broadcast.',
      fansCount: 1000,
      worksCount: 30,
      viewCount: 20,
      city: 'Health City',
      tags: ['dance', 'fitness', 'cooking']
    },
    {
      bloggerId: 5,
      bloggerName: 'Virtual anchor Bear',
      bloggerAvatar: 'https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/custom-render/bear.jpg',
      introduction:
        'Hello everyone, I am the virtual host Xiaoxiong. A little wise man who likes movies, reading and philosophy, I hope to explore the meaning of life with you through live broadcast.',
      fansCount: 1200,
      worksCount: 25,
      viewCount: 18,
      city: 'City of Wisdom',
      tags: ['Movie', 'Literature']
    },
    {
      bloggerId: 6,
      bloggerName: 'Virtual anchor bird',
      bloggerAvatar: 'https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/custom-render/bird.jpeg',
      introduction:
        'Hello everyone, I am the virtual anchor Xiaoniao. I like singing, acting and variety shows. I hope to be happy with everyone through the live broadcast.',
      fansCount: 900,
      worksCount: 12,
      viewCount: 8,
      city: 'Happy City',
      tags: ['music', 'performance', 'variety']
    }
  ],
  defaultRowHeight: 40,
  customMergeCell: (col, row, table) => {
    if (col >= 1 && col < 4 && row === table.rowCount - 2) {
      return {
        range: {
          start: {
            col: 1,
            row: table.rowCount - 2
          },
          end: {
            col: 4,
            row: table.rowCount - 2
          }
        },
        customLayout: args => {
          const { table, row, col, rect } = args;
          const { height, width } = rect || table.getCellRect(col, row);
          const container = (
            <VGroup
              attribute={{
                id: 'container',
                width,
                height,
              }}
            >
              <VRect
                attribute={{
                  id: 'rect1',
                  x: 100,
                  height,
                  width: 90,
                  fill: 'red',
                }}
              ></VRect>
              <VText attribute={{
                x: 120,
                y: 25,
                id: 'text1',
                fill: '#000',
                text: 'VisActor',
                fontSize: 14,
                fontFamily: 'sans-serif',
              }}></VText>
              <VRect
                attribute={{
                  fill: 'blue',
                  id: 'rect2',
                  width: 90,
                  height,
                  x: 190,
                }}
              ></VRect>
              <VText attribute={{
                x: 200,
                y: 25,
                id: 'text2',
                fill: '#000',
                text: 'VisActor1',
                fontSize: 14,
                fontFamily: 'sans-serif',
              }}></VText>
            </VGroup>
          );
          return {
            rootContainer: container,
            renderDefault: false
          };
        }
      };
    }
  }
};

const instance = new VTable.ListTable(document.getElementById(CONTAINER_ID), option);
window.tableInstance = instance;

可以贴到站点试一下https://www.visactor.io/vtable/demo/custom-render/custom-merge-layout
image

@DearChen
Copy link
Author

DearChen commented May 29, 2024

image

嗯 我考虑过了用 customMergeCell 来指定合并单元格,但是这样会对单元格的选中有影响,合并单元格后再选中就会出现跨列了,我打算把列再多分一些,一天再划分四格,再做单元格合并。这样效果应该就可以了。谢谢 [Rui-Sun]的回答

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

3 participants