table合并列

合并单元格

<script type="text/javascript">
$(function(){
               //trackTable为表格的id
    for(var col=0;col<trackTable.rows[1].cells.length;col++){
        $("#trackTable").rowspan(col);
    }
})
//封装的一个JQuery小插件
jQuery.fn.rowspan = function(colIdx) { 
        return this.each(function(){
            var that;
            $('tr', this).each(function(row) {
                $('td:eq('+colIdx+')', this).filter(':visible').each(function(col) {
                    if (that!=null && $(this).html() == $(that).html() && $(this).html() != '&nbsp;' && $(that).html() != '&nbsp;') {
                        rowspan = $(that).attr("rowSpan");
                        if (rowspan == undefined) {
                            $(that).attr("rowSpan",1);
                            rowspan = $(that).attr("rowSpan"); }
                            rowspan = Number(rowspan)+1;
                            $(that).attr("rowSpan",rowspan);
                            $(this).hide();
                        } else {
                            that = this;
                        }
                    });
                });
            });
          }
</script>

注:本篇跟其他帖子有雷同的地方,我只是借用并修改,望原作者理解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
antd table 合并可以通过设置表格的 column 属性中的 render 函数来实现。具体步骤如下: 1. 在 column 中设置需要合并的 dataIndex 和 render 函数。 2. 在 render 函数中,判断当前单元格是否需要合并,如果需要,则返回一个包含合并信息的对象,否则返回单元格的值。 3. 在表格的 rowSpan 和 colSpan 属性中设置需要合并的行数和数。 4. 如果需要在合并后的单元格中显示图片,可以在 render 函数中返回一个包含图片的 JSX 元素。 下面是一个示例代码,用于将表格中的第一和第二合并,并在合并后的单元格中显示图片: ``` import { Table } from 'antd'; const dataSource = [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', image: 'https://example.com/image1.png', }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park', image: 'https://example.com/image2.png', }, { key: '3', name: 'Joe Black', age: 32, address: 'Sidney No. 1 Lake Park', image: 'https://example.com/image3.png', }, ]; const columns = [ { title: 'Name', dataIndex: 'name', key: 'name', render: (text, record, index) => { const obj = { children: text, props: {}, }; if (index === 0) { obj.props.rowSpan = 2; } if (index === 1) { obj.props.rowSpan = 0; } return obj; }, }, { title: 'Age', dataIndex: 'age', key: 'age', render: (text, record, index) => { const obj = { children: text, props: {}, }; if (index === 0) { obj.props.rowSpan = 2; } if (index === 1) { obj.props.rowSpan = 0; } return obj; }, }, { title: 'Address', dataIndex: 'address', key: 'address', }, { title: 'Image', dataIndex: 'image', key: 'image', render: (text, record, index) => { if (index === 0) { return <img src={text} alt="image" />; } return null; }, }, ]; const DemoTable = () => { return <Table dataSource={dataSource} columns={columns} />;}; ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

行云的逆袭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值