expandIconColumnIndex、expandIcon,使用ant design中 expandedRowRender 展开额外行自定义图标位置和样式

16 篇文章 0 订阅
8 篇文章 0 订阅
<template>
  <a-table
    :columns="columns"
    :data-source="data"
    :expandRowByClick="false"
    :expandIconAsCell="false"
    :expandIconColumnIndex="4"
    :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
    :expandIcon="(props)=>this.customExpandIcon(props)">

    <a slot="action" slot-scope="text" href="javascript:;">Delete</a>
    <p slot="expandedRowRender" slot-scope="record" style="margin: 0">这里是额外展开的行 {{ record.description }}</p>
    

  </a-table>
</template>
<script>
const columns = [
  { title: "Name", dataIndex: "name", key: "name" },
  { title: "Age", dataIndex: "age", key: "age" },
  { title: "Address", dataIndex: "address", key: "address" },
  {
    title: "Action",
    dataIndex: "",
    key: "x",
    scopedSlots: { customRender: "action" }
  }
];

const data = [
  {
    key: 1,
    name: "John Brown",
    age: 32,
    address: "New York No. 1 Lake Park",
    description:
      "My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park."
  },
  {
    key: 2,
    name: "Jim Green",
    age: 42,
    address: "London No. 1 Lake Park",
    description:
      "My name is Jim Green, I am 42 years old, living in London No. 1 Lake Park."
  },
  {
    key: 3,
    name: "Joe Black",
    age: 32,
    address: "Sidney No. 1 Lake Park",
    description:
      "My name is Joe Black, I am 32 years old, living in Sidney No. 1 Lake Park."
  }
];

export default {
  data() {
    return {
      selectedRowKeys: [], // Check here to configure the default column
      data,
      columns
    };
  },
methods : {
     onSelectChange(selectedRowKeys) {
      console.log('selectedRowKeys changed: ', selectedRowKeys);
      this.selectedRowKeys = selectedRowKeys;
    },
    customExpandIcon(props){
        console.log(props)
        // if(props.record.children.length > 0){
            if (props.expanded) {
                return <a style={{ color: 'black',marginRight:8 }} onClick={e => {
                    props.onExpand(props.record, e);
                }}><a-button type="link">关闭详情</a-button></a>
            } else {
                return <a style={{ color: 'black' ,marginRight:8 }} onClick={e => {
                    props.onExpand(props.record, e);
                }}><a-button type="link">查看详情</a-button></a>
            }
        // }else{
        //     return <span style={{marginRight:8 }}></span>
        // }
    }
}
};
</script>

在这里插入图片描述

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值