首页 > 其他分享 >推荐 vue2、vue3 中功能最强大的表格组件,性能最强大的表格组件推荐、可编辑表格推荐

推荐 vue2、vue3 中功能最强大的表格组件,性能最强大的表格组件推荐、可编辑表格推荐

时间:2024-11-21 15:28:44浏览次数:1  
标签:name 表格 age id role address 组件 sex 推荐

vxe-table 是一个vue的表格组件,支持可编辑和虚拟滚动高性能表格,公司使用了几年的表格,grid 渲染器扩展功能非常强大。

npm install [email protected] [email protected]
// ...
import VxeUI from 'vxe-pc-ui'
import 'vxe-pc-ui/lib/style.css'
import VxeUITable from 'vxe-table'
import 'vxe-table/lib/style.css'
// ...

createApp(App).use(VxeUI).use(VxeUITable).mount('#app')
// ...

基础使用

<template>
  <div>
    <vxe-table
      :data="tableData">
      <vxe-column type="seq" width="70"></vxe-column>
      <vxe-column field="name" title="Name"></vxe-column>
      <vxe-column field="sex" title="Sex"></vxe-column>
      <vxe-column field="age" title="Age"></vxe-column>
    </vxe-table>
  </div>
</template>

<script>
export default {
  data () {
    const tableData = [
      { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
      { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
      { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
      { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
    ]
    return {
      tableData
    }
  }
}
</script>

多选

单选

单元格合并

标题前缀提示

冻结列

树表格

<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script>
export default {
  data () {
    const gridOptions = {
      border: true,
      treeConfig: {
        rowField: 'id',
        childrenField: 'children'
      },
      columns: [
        { type: 'seq', width: 70 },
        { field: 'name', title: 'Name', minWidth: 300, treeNode: true },
        { field: 'size', title: 'Size' },
        { field: 'type', title: 'Type' },
        { field: 'date', title: 'Date' }
      ],
      data: [
        { id: 10000, name: 'Test1', type: 'mp3', size: 1024, date: '2020-08-01' },
        {
          id: 10050,
          name: 'Test2',
          type: 'mp4',
          size: 0,
          date: '2021-04-01',
          children: [
            {
              id: 24300,
              name: 'Test3',
              type: 'avi',
              size: 1024,
              date: '2020-03-01',
              children: [
                { id: 20045, name: 'Test4', type: 'html', size: 600, date: '2021-04-01' },
                {
                  id: 10053,
                  name: 'Test5',
                  type: 'avi',
                  size: 0,
                  date: '2021-04-01',
                  children: [
                    { id: 24330, name: 'Test6', type: 'txt', size: 25, date: '2021-10-01' },
                    { id: 21011, name: 'Test7', type: 'pdf', size: 512, date: '2020-01-01' },
                    { id: 22200, name: 'Test8', type: 'js', size: 1024, date: '2021-06-01' }
                  ]
                }
              ]
            }
          ]
        },
        {
          id: 23666,
          name: 'Test9',
          type: 'xlsx',
          size: 2048,
          date: '2020-11-01',
          children: [
            {
              id: 23677,
              name: 'Test10',
              type: 'js',
              size: 1024,
              date: '2021-06-01',
              children: [
                { id: 23671, name: 'Test11', type: 'js', size: 1024, date: '2021-06-01' },
                { id: 23672, name: 'Test12', type: 'js', size: 1024, date: '2021-06-01' }
              ]
            },
            {
              id: 23688,
              name: 'Test13',
              type: 'js',
              size: 1024,
              date: '2021-06-01',
              children: [
                { id: 23681, name: 'Test14', type: 'js', size: 1024, date: '2021-06-01' },
                { id: 23682, name: 'Test15', type: 'js', size: 1024, date: '2021-06-01' }
              ]
            }
          ]
        },
        {
          id: 24555,
          name: 'Test16',
          type: 'avi',
          size: 224,
          date: '2020-10-01',
          children: [
            { id: 24566, name: 'Test17', type: 'js', size: 1024, date: '2021-06-01' },
            { id: 24577, name: 'Test18', type: 'js', size: 1024, date: '2021-06-01' }
          ]
        }
      ]
    }
    return {
      gridOptions
    }
  }
}
</script>

行与列拖拽调整顺序

<template>
  <div>
    <vxe-button status="success" @click="resultEvent">获取数据</vxe-button>
    <vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script>
export default {
  data () {
    const gridOptions = {
      border: true,
      columnConfig: {
        useKey: true,
        drag: true
      },
      rowConfig: {
        useKey: true,
        drag: true
      },
      columns: [
        { field: 'name', title: 'Name' },
        { field: 'role', title: 'Role', dragSort: true },
        { field: 'sex', title: 'Sex' },
        { field: 'age', title: 'Age' },
        { field: 'address', title: 'Address' }
      ],
      data: [
        { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
        { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
        { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
        { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
      ]
    }
    return {
      gridOptions
    }
  },
  methods: {
    resultEvent () {
      const $grid = this.$refs.gridRef
      if ($grid) {
        const { visibleColumn } = $grid.getTableColumn()
        console.log(visibleColumn)
      }
    }
  }
}
</script>

可编辑表格

<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script>
export default {
  data () {
    const gridOptions = {
      border: true,
      showOverflow: true,
      editConfig: {
        trigger: 'click',
        mode: 'cell'
      },
      columns: [
        { type: 'seq', width: 70 },
        { field: 'name', title: 'Name', editRender: { name: 'input' } },
        { field: 'sex', title: 'Sex', editRender: { name: 'input' } },
        { field: 'age', title: 'Age', editRender: { name: 'input' } }
      ],
      data: [
        { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
        { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
        { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
        { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
      ]
    }
    return {
      gridOptions
    }
  }
}
</script>

数据校验

<template>
  <div>
    <div>
      <vxe-button @click="validEvent">校验变动数据</vxe-button>
      <vxe-button @click="fullValidEvent">校验全量数据</vxe-button>
    </div>
    <vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script>
import { VxeUI } from 'vxe-table'
export default {
  data () {
    const gridOptions = {
      border: true,
      showOverflow: true,
      keepSource: true,
      height: 300,
      editConfig: {
        trigger: 'click',
        mode: 'row',
        showStatus: true
      },
      editRules: {
        role: [
          { required: true, message: '必须填写' }
        ]
      },
      columns: [
        { type: 'checkbox', width: 60 },
        { type: 'seq', width: 70 },
        { field: 'name', title: 'Name', editRender: { name: 'VxeInput' } },
        { field: 'role', title: 'Role', editRender: { name: 'VxeInput' } },
        { field: 'sex', title: 'Sex', editRender: { name: 'VxeInput' } },
        { field: 'age', title: 'Age', editRender: { name: 'VxeInput' } },
        { field: 'date', title: 'Date', editRender: { name: 'VxeInput' } }
      ],
      data: [
        { id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, address: 'test abc' },
        { id: 10002, name: '', role: 'Test', sex: '1', age: 22, address: 'Guangzhou' },
        { id: 10003, name: 'Test3', role: 'PM', sex: '', age: 32, address: 'Shanghai' },
        { id: 10004, name: 'Test4', role: 'Designer', sex: '', age: 23, address: 'test abc' },
        { id: 10005, name: '', role: '', sex: '1', age: 30, address: 'Shanghai' },
        { id: 10006, name: 'Test6', role: 'Designer', sex: '1', age: 21, address: 'test abc' }
      ]
    }
    return {
      gridOptions
    }
  },
  methods: {
    async validEvent () {
      const $grid = this.$refs.gridRef
      if ($grid) {
        const errMap = await $grid.validate()
        if (errMap) {
          VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
        } else {
          VxeUI.modal.message({ status: 'success', content: '校验成功!' })
        }
      }
    },
    async fullValidEvent () {
      const $grid = this.$refs.gridRef
      if ($grid) {
        const errMap = await $grid.validate(true)
        if (errMap) {
          VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
        } else {
          VxeUI.modal.message({ status: 'success', content: '校验成功!' })
        }
      }
    }
  }
}
</script>

表格搜索

<template>
  <div>
    <p>
      <vxe-input v-model="filterName" type="search" placeholder="试试全表搜索" @keyup="searchEvent"></vxe-input>
    </p>

    <vxe-grid v-bind="gridOptions" class="mylist-grid"></vxe-grid>
  </div>
</template>

<script>
import XEUtils from 'xe-utils'
export default {
  data () {
    const tableAllData = [
      { id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, amount: 888, address: 'test abc' },
      { id: 10002, name: 'Test2', role: 'Test', sex: '1', age: 22, amount: 666, address: 'Guangzhou' },
      { id: 10003, name: 'Test3', role: 'PM', sex: '1', age: 32, amount: 89, address: 'Shanghai' },
      { id: 10004, name: 'Test4', role: 'Designer', sex: '0', age: 23, amount: 1000, address: 'test abc' },
      { id: 10005, name: 'Test5', role: 'Develop', sex: '0', age: 30, amount: 999, address: 'Shanghai' },
      { id: 10006, name: 'Test6', role: 'Designer', sex: '0', age: 21, amount: 998, address: 'test abc' },
      { id: 10007, name: 'Test7', role: 'Test', sex: '1', age: 29, amount: 2000, address: 'test abc' },
      { id: 10008, name: 'Test8', role: 'Develop', sex: '1', age: 35, amount: 999, address: 'test abc' },
      { id: 10009, name: 'Test9', role: 'Test', sex: '1', age: 26, amount: 2000, address: 'test abc' },
      { id: 100010, name: 'Test10', role: 'Develop', sex: '1', age: 21, amount: 666, address: 'test abc' }
    ]
    const gridOptions = {
      border: true,
      height: 400,
      columnConfig: {
        useKey: true
      },
      rowConfig: {
        useKey: true
      },
      columns: [
        { type: 'seq', width: 70 },
        { field: 'name', title: 'Name', type: 'html' },
        { field: 'sex', title: 'Sex', type: 'html' },
        { field: 'age', title: 'Age', type: 'html' },
        { field: 'address', title: 'Address', type: 'html' }
      ],
      data: []
    }
    return {
      gridOptions,
      filterName: '',
      tableAllData
    }
  },
  methods: {
    handleSearch () {
      const filterVal = String(this.filterName).trim().toLowerCase()
      if (filterVal) {
        const filterRE = new RegExp(filterVal, 'gi')
        const searchProps = ['name', 'role', 'age', 'address']
        const rest = this.tableAllData.filter(item => searchProps.some(key => String(item[key]).toLowerCase().indexOf(filterVal) > -1))
        this.gridOptions.data = rest.map(row => {
          // 搜索为克隆数据,不会污染源数据
          const item = XEUtils.clone(row)
          searchProps.forEach(key => {
            item[key] = String(item[key]).replace(filterRE, match => `<span class="keyword-highlight">${match}</span>`)
          })
          return item
        })
      } else {
        this.gridOptions.data = this.tableAllData
      }
    },
    // 节流函数,间隔500毫秒触发搜索
    searchEvent: XEUtils.throttle(function () {
      this.handleSearch()
    }, 500, { trailing: true, leading: true })
  },
  created () {
    this.handleSearch()
  }
}
</script>

<style lang="scss" scoped>
.mylist-grid {
  ::v-deep(.keyword-highlight)  {
    background-color: #FFFF00;
  }
}
</style>

标签:name,表格,age,id,role,address,组件,sex,推荐
From: https://www.cnblogs.com/qaz666/p/18560889

相关文章

  • vxe-table 表格导出 txt 格式文件
    导出Txt文件打卡txt文件<template><div><vxe-button@click="exportEvent">直接导出Txt文件</vxe-button><vxe-tableshow-footerref="tableRef":export-config="{}":footer-d......
  • vxe-table 表格导出 xml 格式文件
    导出XML文件打开xml文件,部分截图<template><div><vxe-button@click="exportEvent">直接导出XML文件</vxe-button><vxe-tableshow-footerref="tableRef":export-config="{}":foo......
  • ssm毕设影院推荐系统程序+论文+部署
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容一、研究背景随着电影产业的蓬勃发展,影院上映的影片数量日益增多。观众在选择影片时往往面临着众多的选择,信息过载的问题愈发严重 [1] 。传统的依靠海报、......
  • vxe-table 集成 echarts 实现单元格图表功能,柱状图、饼图、折线图、右键菜单加载表格
    实现表格通过右键菜单渲染折线图、饼图、柱状图等<template><div><vxe-gridv-bind="gridOptions"@menu-click="menuClickEvent"></vxe-grid></div></template><script>exportdefault{data(......
  • 分享个人在项目中使用过最强的企业级表格、顶级表格控件推荐 vxe-table
    专业的表格控件SpreadJS、ad-grid、vxe-table对比评测,仅对个人实际使用中的开发体验分享、仅供参考做过很多大型项目,ERP、企业内部管理系统,一个系统好不好用基本就是看表格做得好不好了。一般业务的列表页面、增删改查页面、表单页面等。总结实现Excel在线协同功能就选Spr......
  • Element Plus组件el-select回显异常
    前情公司有经常需要做一些后台管理页面,我们选择了ElementPlus,它是基于Vue3,面向设计师和开发者的组件库,是Vue框架生态中比较火的UI组件库,组件库丰富易用,组件链接:一个Vue3UI框架|ElementPlus坑位最近在开发一个需求,需要使用el-select组件实现多选,但是在回显的时候发......
  • 2024网络安全学习路线 非常详细 推荐学习
    关键词:网络安全入门、渗透测试学习、零基础学安全、网络安全学习路线首先咱们聊聊,学习网络安全方向通常会有哪些问题1、打基础时间太长学基础花费很长时间,光语言都有几门,有些人会倒在学习linux系统及命令的路上,更多的人会倒在学习语言上;2、知识点掌握程度不清楚对于网......
  • 界面控件DevExpress Blazor UI v24.1新版亮点:发布全新文件输入等组件
    DevExpress BlazorUI组件使用了C#为BlazorServer和BlazorWebAssembly创建高影响力的用户体验,这个UI自建库提供了一套全面的原生BlazorUI组件(包括PivotGrid、调度程序、图表、数据编辑器和报表等)。DevExpress Blazor控件目前已经升级到v24.1版本了,此版本发布了全新文件输入......
  • 办公必备!4款Win电脑实用的效率工具推荐
    在日常的办公场景中,拥有一些高效实用的工具能够极大地提升我们的工作效率和质量。今天就给大家推荐四款Windows电脑上的宝藏效率工具,让你的办公如虎添翼。1、飞书先进企业协作与管理平台。提供一站式整合即时沟通、音视频会议、飞书文档等办公协作套件,还提供项目与组织管理工......
  • Vue3.2+TS+arco-design报表封装,所有的报表页面皆可用一个组件进行完成
    多功能表格统一封装在我们进行后台管理系统开发的时候,一定少不了报表的开发,报表无非就是筛选,统计,分页等功能,但是一旦报表多了起来之后,每次都去开发一个表格,每次都去写一个table,还要加分页,就显得非常没有必要所以我封装了一个多功能表格,以后每次,只需要导入这个组件,便可以......