Ant Design of Vue表格排序以及自定义样式

1.自定义样式

{
          title: '区域',
          dataIndex: 'pathName',
          key: 'pathName',
            //控制单列样式
          customCell: (record, rowIndex) => {
            return {
              style: {
                'background-color': '#063d79'
              },
              class: ['boxColor' + (rowIndex % 2), 'one']
            }
          },
            //排序
    sorter: (a, b) => {
            let aTime = a.startTime ? new Date(a.startTime).getTime() : 0 // 需要先转换成时间戳
            let bTime = b.startTime ? new Date(b.startTime).getTime() : 0
            return aTime - bTime
          },
          width: this.$global.tableTitleWidth.pathname,//宽度
            //自定义内容以及单个点击事件
          customRender: (text, record, index) => {
            if (text) {
              if (text) {
                let pathNames = text.split('/')[1] + (text.split('/')[2] ? '/' + text.split('/')[2] : '')
                return (
                  <div class="ellipsisText"  onClick={(e) => this.onbasicinformation(record)}>
                    <a-tooltip placement="topLeft" overlayClassName="ellipsisTexttooltip">
                      <template slot="title">
                        <span style="color:#000;font-size: 18px;">{pathNames}</span>
                      </template>
                      {pathNames}
                    </a-tooltip>
                  </div>
                )
              } else {
                return '-'
              }
            }
          },
        },

2.排序

根据时间排序

sorter: (a, b) => {
            let aTime = a.startTime ? new Date(a.startTime).getTime() : 0 // 需要先转换成时间戳
            let bTime = b.startTime ? new Date(b.startTime).getTime() : 0
            return aTime - bTime
          },

根据数字排序

 sorter: (a, b) => a.Datas - b.Datas,

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Ant Design of Vue 是一套基于 Vue.js 的 UI 组件库,其中包含了丰富的组件,包括表格组件。下面是一个带分页和多选功能的 Ant Design of Vue 表格示例: ```html <template> <a-table :columns="columns" :data-source="dataSource" :pagination="pagination" row-selection="rowSelection" @change="handleTableChange"> </a-table> </template> <script> export default { data() { return { columns: [ { title: '姓名', dataIndex: 'name' }, { title: '年龄', dataIndex: 'age' }, { title: '地址', dataIndex: 'address' } ], dataSource: [], // 表格数据 pagination: { // 分页配置 current: 1, // 当前页码 pageSize: 10, // 每页显示条数 total: 0 // 数据总条数 }, rowSelection: { // 多选配置 selectedRowKeys: [], onChange: this.handleRowSelectionChange } } }, methods: { // 处理表格变化事件 handleTableChange(pagination) { this.pagination = pagination this.fetchData() }, // 处理多选变化事件 handleRowSelectionChange(selectedRowKeys) { this.rowSelection.selectedRowKeys = selectedRowKeys }, // 获取表格数据 fetchData() { // 发送异步请求获取数据 // ... // 设置表格数据和分页信息 this.dataSource = [] this.pagination.total = 100 } }, mounted() { // 初始化数据 this.fetchData() } } </script> ``` 在上面的代码中,`columns` 数组定义了表格的列信息,`dataSource` 数组存储了表格的数据,`pagination` 对象定义了分页信息,`rowSelection` 对象定义了多选配置。在 `a-table` 组件中,我们将这些配置传递给了组件,并设置了相应的事件回调函数。在 `handleTableChange` 方法中,我们处理了分页变化事件,在 `handleRowSelectionChange` 方法中,我们处理了多选变化事件。`fetchData` 方法用于获取表格数据,我们可以在其中发送异步请求获取数据,并设置表格数据和分页信息。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值