antd 表格表头样式设置及样式自定义方案

话不多说 先上效果图、

首先是样式设置,可以直接对表头添加背景色 字体颜色等 css样式,达到如上图 下单数量 这样的效果 代码如下

html
<div class="editTheForm">
    <a-table bordered
             :data-source="dataSource"
             :pagination='false'
             :columns="columns"
             rowKey="id">
    </a-table> 
</div>




js
columns: [{
          title: '下单数量',
          scopedSlots: { customRender: 'order_num' },
          className: 'colunm-order_num',
        },]

css
.editTheForm >>> .colunm-order_num {
  color: red;
}

自定义样式方案,这种方案可以对表头插入新的数据达到样式多样化,图标插入的效果:

html部分

 <div class="editTheForm">
    <a-table bordered
             ref="table"
             :data-source="dataSource"
             :pagination='false'
             :columns="columns"
             rowKey="id"
             :scroll="{ y: '40vh' }">
      <span slot="custom_price">
        <template>单价/件</template>
        <span class="colunm-order_num">*</span>
      </span>
    </a-table>
</div>

js部分 注意:要将title去掉,用slots,类似于具名插槽的方式

        columns: [{
          slots: { title: 'custom_price' },
          scopedSlots: { customRender: 'price' },
        },]

css部分

.editTheForm >>> .colunm-order_num {
  color: red;
}

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自定义el-table表头,您可以使用以下步骤: 1. 首先,您需要在el-table中使用自定义表头插槽。这可以通过将表头插槽名称设置为“header”来完成。例如: ``` <el-table :data="tableData"> <template slot="header"> <tr> <th>Name</th> <th>Age</th> <th>City</th> </tr> </template> ... </el-table> ``` 2. 您可以在表头插槽中添加任何自定义内容,例如图标、按钮等。 3. 您还可以使用表头插槽来自定义表头样式。例如,您可以添加CSS类或样式属性来更改表头的颜色、字体大小等。例如: ``` <el-table :data="tableData"> <template slot="header"> <tr class="my-custom-header"> <th>Name</th> <th>Age</th> <th>City</th> </tr> </template> ... </el-table> ``` ``` .my-custom-header th { color: red; font-size: 16px; } ``` 4. 您还可以使用el-table表头属性来更改表头的默认样式。例如,您可以更改表头的高度、背景颜色等。例如: ``` <el-table :data="tableData" :header-row-style="{height: '50px', background: 'blue'}"> <template slot="header"> <tr> <th>Name</th> <th>Age</th> <th>City</th> </tr> </template> ... </el-table> ``` 5. 最后,您还可以使用el-table-column的属性来自定义每个列的表头。例如,您可以更改每个列的名称、宽度、对齐方式等。例如: ``` <el-table :data="tableData"> <el-table-column prop="name" label="Name" width="150"></el-table-column> <el-table-column prop="age" label="Age" width="100" align="center"></el-table-column> <el-table-column prop="city" label="City" width="200"></el-table-column> </el-table> ``` 这些是自定义el-table表头的一些基本步骤。您可以根据自己的需求进行更改和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值