当前位置: 首页 > Web前端 > vue.js

antd-design-vueTable(槽槽)动态单元列个性化样式操作

时间:2023-03-31 18:35:37 vue.js

Table(槽槽)通用操作1.scopedSlots属性constcolumns=[..."scopedSlots":{"customRender":"field"//field需要对应页面中的dataIndex字段},]...{{text}}

文档:https://www.antdv.com/compone...动态slot1.和之前的页面不同的是,页面里面写的是哪一列操作字段,dynamic就是字段field不确定,留给用户配置。2.columns中的json很重要1.colProperty可以理解为一个列索引,colProperty的长度取决于数据中有多少列。为什么要建索引,因为考虑到header有多个,遇到children下的字段,找不到它的长度。2、cols为表头显示内容,包含scopedSlots等属性。“colProperty”:[{“sorter”:“0”,“scopedSlots”:0,“dataIndex”:“C1”,“width”:“100”,“fixed”:“false”,“title”:“字段一个”,“对齐”:“中心”},{“排序器”:“0”,“scopedSlots”:1,“dataIndex”:“C2”,“宽度”:“100”,“固定”:“假”,"title":"FieldTwo","align":"center"}],"cols":[{"sorter":false,"dataIndex":"C1","width":100,"fixed":false,"title":"第一场","align":"left","className":"notshow"},{"sorter":"(a,b)=>a.C2-b.C2","scopedSlots":{"customRender":"C2"},"dataIndex":"C2","width":100,"fixed":false,"title":"Field2","align":"left"}],3.操作1.a-table中的列为this.columns.cols...2.slot中的写法,根据this.columns.colProperty中scopedSlots的判断(当然也可以设置type)来开启column的个性化配置{{text}}
{{text}}}
总结1.json配置的关键是创建一个column指数。也就是说,索引的长度取决于数据中有多少列。