动漫设计专业哪个学校比较好,seo标题优化,东莞网站建设手袋加工,北京做网站哪家便宜Table 表格 展示行列数据。 何时使用 当有大量结构化的数据需要展现时#xff1b; 当需要对数据进行排序、搜索、分页、自定义操作等复杂行为时。 最近在写vueantd的框架#xff0c;遇到一个需求#xff1a;就是要实现table表格的动态列#xff0c;并且相应的表头要实现下拉…Table 表格 展示行列数据。 何时使用 当有大量结构化的数据需要展现时 当需要对数据进行排序、搜索、分页、自定义操作等复杂行为时。 最近在写vueantd的框架遇到一个需求就是要实现table表格的动态列并且相应的表头要实现下拉选择的效果最后点击保存时要将下拉的内容拼接到对应的列上面去。 在Table中dataSource和columns里的数据都需要指定key值。对于dataSource默认将每列数据的key作为唯一标识。 如果数据中没有这个属性务必使用rowKey来指定数据列的主键。如果没有指定控制台会出现缺少key的提示表格组件也会出现各类奇怪的错误。 table组件实现动态列表头下拉选择功能 Table 表格何时使用 效果图table组件实现动态列table组件表头自定义——slots: { title: 无主列 index }1.使用slots:{title:无主列}2.在table组件中使用slotxxxx的方式来处理 效果图 上面的[序号物料名称型号品牌封装参数位号供料方式单片用量需求用量类目类别SMT套数]都是固定列 动态列是上图中红框框住的部分 table组件实现动态列
先看数据结构 要求根据第一条数据中的noBelongCols字段创建动态列。 1.tableListtable表格列表数据 2.noBelongCols动态列参数长度就是动态列的长度 3.noBelongTypes表头的下拉列参数 changeColumns(){let noBelongCols this.tableList this.tableList[0] this.tableList[0].noBelongCols;console.log(noBelongCols, noBelongCols, this.columns);this.noBelongCols noBelongCols;this.noBelongTypes [];noBelongCols noBelongCols.forEach((be, index) {this.columns.push({slots: { title: 无主列 index },type: string,dataIndex: 无主列 index,width: 110,scopedSlots: { customRender: 无主列 index },});this.noBelongTypes.push(undefined);this.tableList.forEach((table) {table[无主列 index] table[noBelongCols][index];});});this.columns.push({title: 操作,scopedSlots: { customRender: action },align: center,width: 60,fixed: right,});
}table组件表头自定义——slots: { title: ‘无主列’ index }
由于动态列的长度不固定因此需要用v-for进行遍历遍历出多列。 v-for(be, bIndex) in noBelongCols :keybIndex :slot无主列 bIndexa-table:rowKey(r, i) i.toString():columnscolumns:dataSourcetableList
divv-for(be, bIndex) in noBelongCols:keybIndex:slot无主列 bIndexa-select v-modelnoBelongTypes[bIndex] stylewidth: 100pxa-select-optionv-foritem in titleOptions:keyitem:valueitem{{ item }}/a-select-option/a-select/div
/a-table表格头部自定义的处理方法
1.使用slots:{title:无主列} 自定义表头slots:{title:无主列index} 自定义表格内容scopedSlots:{customRender:无主列index} 遍历动态列的时候设置自定义表头和自定义表格内容
this.columns.push({slots: { title: 无主列 index },type: string,dataIndex: 无主列 index,width: 110,scopedSlots: { customRender: 无主列 index },
});2.在table组件中使用slotxxxx的方式来处理
最终代码如下
divv-for(be, bIndex) in noBelongCols:keybIndex:slot无主列 bIndex
a-select v-modelnoBelongTypes[bIndex] stylewidth: 100pxa-select-optionv-foritem in titleOptions:keyitem:valueitem{{ item }}/a-select-option/a-select
/div完成多多积累多多收获
下面内容与文章相关不大只是为了凑字数可忽略 table组件主要用于大量结构化的数据需要展现时使用在各端应用开发中使用非常广泛达到几乎必用的地步。在原生ios开发中通常需要自定义cell来进行数据的展示antd 的table组件功能相当强大能实现的功能覆盖范围也相当广泛本文只是简单介绍一下最基本的用法有兴趣的可以直接去官网上看示例更丰富而且都带有效果展示。 首先指定表格的数据源 dataSource 为一个数组 在数据较多会自动分页展示每一列会根据内容的长度自动撑长上手使用非常简单通常PC上对表格会有一些编辑等操作在原生ios中需要自己布局、定义方法等一系列操作antd table则只需要在列名称中添加链接就好 自定义andt table表格样式的方式也比较多上述方法可能会引起全局改变如果只是改变代码中一个table则需要注意以下。以上只是介绍的最最最基础的用法还有很多高级一些的方法大家可以去官网细看。 值得一提的是表格的样式是默认的需要修改的话要自己改变样式可以参考以下方法 .ant-table{:global {width: 98%;margin-left: 1%;.ant-table-thead tr th, .ant-table-tbody tr td {padding: 6px 8px !important;}.ant-table-thead tr th {background-color: #242542;color: white;}.ant-table-thead tr th:hover {background-color: #535781;}.ant-table-thead tr th.ant-table-column-has-actions.ant-table-column-has-sorters:hover {background: rgb(201, 223, 11);}.ant-table-content { background-color: #343655; color: white;}.ant-table-tbody tr:hover td{background-color:rgba(106, 178, 245, 0.5) ! important;}}
}