New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sw-table

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sw-table

一个基于Vue的PC端虚拟表格组件,支持虚拟行与虚拟列以及大部分el-table相关的属性

latest
Source
npmnpm
Version
0.2.3
Version published
Maintainers
1
Created
Source

Sw-Table

Sw-Table是一个基于Vue的PC端表格组件,支持虚拟行/虚拟列以及大部分el-table相关属性

安装

npm install sw-table

使用

import Vue from 'vue'
import SwTable from 'sw-table'
import 'sw-table/dist/sw-table.css'

Vue.use(SwTable)

示例

注意:sw-table使用的属性是table-data而不是data

<template>
    <sw-table :table-data="tableData">
      <sw-table-column
        prop="date"
        label="日期"
        width="180">
      </sw-table-column>
      <sw-table-column
        prop="name"
        label="姓名"
        width="180">
      </sw-table-column>
      <sw-table-column
        prop="address"
        label="地址">
      </sw-table-column>
    </sw-table>
  </template>

  <script>
    export default {
      data() {
        return {
          tableData: [{
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄'
          }, {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1519 弄'
          }, {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1516 弄'
          }]
        }
      }
    }
  </script>

API

Table Attributes

参数说明类型可选值默认值
table-data显示的数据 (el-table中为data)array
heightTable 的高度,默认为自动高度。string/number
max-heightTable 的最大高度。合法的值为数字或者单位为 px 的高度。string/number
stripe是否为斑马纹 tablebooleanfalse
border是否带有纵向边框booleanfalse
highlight-current-row是否要高亮当前行booleanfalse
row-class-name行的 className 的回调方法,也可以使用字符串为所有行设置一个固定的 className。Function({row, rowIndex})/String
row-style行的 style 的回调方法,也可以使用一个固定的 Object 为所有行设置一样的 Style。Function({row, rowIndex})/Object
cell-class-name单元格的 className 的回调方法,也可以使用字符串为所有单元格设置一个固定的 className。Function({row, column, rowIndex, columnIndex})/String
cell-style单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有单元格设置一样的 Style。Function({row, column, rowIndex, columnIndex})/Object
header-row-class-name表头行的 className 的回调方法,也可以使用字符串为所有表头行设置一个固定的 className。Function({row, rowIndex})/String
header-row-style表头行的 style 的回调方法,也可以使用一个固定的 Object 为所有表头行设置一样的 Style。Function({row, rowIndex})/Object
header-cell-class-name表头单元格的 className 的回调方法,也可以使用字符串为所有表头单元格设置一个固定的 className。Function({row, column, rowIndex, columnIndex})/String
header-cell-style表头单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有表头单元格设置一样的 Style。Function({row, column, rowIndex, columnIndex})/Object
default-sort默认的排序列的 prop 和顺序。它的prop属性指定默认的排序的列,order指定默认排序的顺序Objectorder: ascending, descending如果只指定了prop, 没有指定order, 则默认顺序是ascending
span-method合并行或列的计算方法Function({ row, column, rowIndex, columnIndex })

Table Events

事件名说明参数
select当勾选数据行的 Checkbox 时触发的事件selection, row
select-all当勾选全选 Checkbox 时触发的事件selection
cell-mouse-enter当单元格 hover 进入时会触发该事件{ row, column, rowIndex, columnIndex }
cell-mouse-leave当单元格 hover 退出时会触发该事件{ row, column, rowIndex, columnIndex }
cell-click当某个单元格被点击时会触发该事件{ row, column, rowIndex, columnIndex }
cell-dblclick当某个单元格被双击击时会触发该事件{ row, column, rowIndex, columnIndex }
row-click当某一行被点击时会触发该事件{ row, rowIndex }
row-contextmenu当某一行被鼠标右键点击时会触发该事件{ row, rowIndex }
row-dblclick当某一行被双击时会触发该事件{ row, rowIndex }
header-click当某一列的表头被点击时会触发该事件{ rowIndex, columnIndex }
header-contextmenu当某一列的表头被鼠标右键点击时触发该事件{ rowIndex, columnIndex }
sort-change当表格的排序条件发生变化的时候会触发该事件{ column, prop, order }
current-change当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性currentRow, oldCurrentRow
header-dragend当拖动表头改变了列的宽度的时候会触发该事件newWidth, oldWidth, column

Table Methods

方法名说明参数
clearSelection用于多选表格,清空用户的选择
toggleRowSelection用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)row, selected
toggleAllSelection用于多选表格,切换所有行的选中状态-
setCurrentRow用于单选表格,设定某一行为选中行,如果调用时不加参数,则会取消目前高亮行的选中状态。row
clearSort用于清空排序条件,数据会恢复成未排序的状态
refresh强行对 Table 进行重新布局。
sort手动对 Table 进行排序。参数prop属性指定排序列,order指定排序顺序。prop: string, order: string

Table Slot

name说明
append插入至表格最后一行之后的内容,如果需要对表格的内容进行无限滚动操作,可能需要用到这个 slot。

Table-column Attributes

参数说明类型可选值默认值
type对应列的类型。如果设置了 selection 则显示多选框;如果设置了 index 则显示该行的索引(从 1 开始计算);stringselection/index
index如果设置了 type=index,可以通过传递 index 属性来自定义索引number, Function(index)
label显示的标题string
prop对应列内容的字段名,也可以使用 property 属性string
width对应列的宽度string, number
min-width对应列的最小宽度,与 width 的区别是 width 是固定的,min-width 会把剩余宽度按比例分配给设置了 min-width 的列string, number
fixedtrue 表示固定在左侧booleantrue, false
sortable对应列是否可以排序booleantrue, false
resizable对应列是否可以通过拖动改变宽度booleantrue
align对齐方式Stringleft/center/rightleft
header-align表头对齐方式,若不设置该项,则使用表格的对齐方式Stringleft/center/right
class-name列的 classNamestring
selectable仅对 type=selection 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选Function(row, rowIndex, cellType)
reserve-selection仅对 type=selection 的列有效,类型为 Boolean,为 true 则会在数据更新之后保留之前选中的数据(需指定 row-keyBooleanfalse

Table-column Scoped Slot

name说明
自定义列的内容,参数为 { row, column, $index }
header自定义表头的内容. 参数为 { column, $index }

Keywords

sw-table

FAQs

Package last updated on 11 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts