0.2.1 • Published 4 years ago

ac-hand-table v0.2.1

Weekly downloads
11
License
MIT
Repository
github
Last release
4 years ago

电子表格 HandTable

ac-hand-table 是基于 handsontable 的适用于 React 框架的电子表格,它提供了数据绑定、数据验证、行过滤、列排序、表格多选、表格样式、表头交互、表头拖拽、行高拖拽、行交换等操作

如何使用

使用 npm 安装最新版本

$ npm install ac-hand-table  --save

引入
import AcHandTable from 'ac-hand-table';
样式
import 'ac-hand-table/dist/index.css';

代码演示

API

AcHandTable

参数说明类型默认值
id组件唯一idstring-
data表格数据数据array[]
columns列的配置表,具体配置见下表array[]
language表格语言'zh-CN'或 'en-US'或 'zh-TW''zh-CN'
rowHeaders表头信息booleanarrayfunction (index)=>{}true
colWidths列宽number 100或 string '100px'或 array 100,200func (index)=>{}-
rowHeights列宽number 100或 string '100px'或 array 100,200func (index)=>{}-
width表格总宽度'%' 或 'px'-
height表格总高度'%' 或 'px' 或 'auto'-
multiSelect是否含有多选框booleantrue
manualColumnResize是否列宽可以拖动booleantrue
manualColumnMove是否列可以交换booleanfalse
manualRowResize是否行高可以拖动booleanfalse
manualRowMove是否行可以交换booleanfalse
fixedColumnsLeft列左固定number-
fixedColumnsRight列右固定number-
fixedRowsBottom行头固定number-
fixedRowsTop行头固定number-
manualColumnFreeze是否开启固定列booleantrue
copyPaste是否可以复制粘贴booleantrue
customBorders是否开启边框设置booleantrue
copyable是否开启键盘复制booleantrue
allowInsertColumn是否开启插入列booleantrue
allowInsertRow是否开启插入行booleantrue
multiColumnSorting是否列可以排序booleantrue
dropdownMenu表上下文下拉菜单booleanarray 见下表 dropdownMenu contextMenufalse
contextMenu行上下文下拉菜单booleanarray 见下表 dropdownMenu contextMenufalse
filters表头下拉菜单中是否启动过滤器booleanfalse
stretchH表宽度不等于所有列宽的计算总和时,列宽设置'none'或 'all' 或'last''none'
rowStyle行设置样式func-
activeHeaderClassName选中列标题样式strig-
columnHeaderHeight列表头高number25
fixedShadow是否固定表格阴影booleanfalse
fixedColumnsLeft固定表格列number-
fixedRowsTop是否固定表格顶部number-
fixedRowsBottom是否固定表格底部number-
nestedHeaders多表头array [['a','b']]或者[['a',{label:'b',colspan:2}]]-
fillHandle自动填充设置booleanstring('vertical' or 'horizontal') 或者 object见下表 fillHandle'vertical'

dropdownMenu contextMenu

说明额外条件
row_above在选中行上方插入行-
row_below在选中行下方插入行-
col_left插入列左侧操作-
col_right插入列右侧操作-
---------分隔器-
remove_row删除行动作-
remove_col删除列操作-
clear_column清除列值操作-
undo撤消操作undoRedo已开启-
redo重做动作undoRedo已开启
make_read_only进行只读操作-
alignment对齐操作-
cut剪切操作copyPaste打开
copy复制操作copyPaste打开
merge_cells合并单元格-
freeze_column锁定列操作manualColumnFreeze已开启
unfreeze_column解锁列操作manualColumnFreeze已开启
borders自定义边框操作customBorders已开启
allowEmpty是否日期可以值为空booleantrue

Column

参数说明类型默认值
data列的键,支持'date.xx'string-
type数据类型 text numeric date time checkbox select dropdown autocomplete password refMultipleTable refTreeWithInput refTreeTableWithInput refTreeTransferWithInputstringtrue
className样式名string-
readOnly是否数据仅可读booleanfalse
readOnlyCellClassName自定义只读表格样式string-
textTooltip表格内容超出表格的宽出现 ...booleantrue
editor是否数据可以编辑booleantrue
strict是否输入到单元格的值区分大小写booleanfalse
placeholder单元格占位文字string-
tableClassName表格样式类名string-
dateFormat日期格式string-
correctFormat当前日期是否格式化booleantrue
defaultDate默认日期string-
source数据类型 'autocomplete' 或 'dropdown' 数据源array func (query,callback)=>{}''
numericFormat数字类型格式化object-
multiColumnSorting打开多列排序boolean 或 objectfalse
allowInvalid数据校验失败是否可以操作其他表格booleantrue
allowEmpty是否日期可以值为空booleantrue
validator自定义验证方法func (value,callback)=>{}-
onClick表格点击事件func (rowData, rowNum, value)=>{}-
dblClick表格双击事件func (rowData, rowNum, value)=>{}-
onChangeCell表格值变化事件func (rowData, rowNum)=>{}-
refSource参照数据回调func (value, type, callback)=>{} 'type'值为auto tree table-
refOnChange参照选中回调func (refData, rowData, rowNum)=>{}-
refConfig参照配置见下表 refConfig-
customValue自定义表格内容渲染,通常用于表格联动(rowData)=>{}-
renderer自定义表格渲染,支持dom(instance, td, row, col, prop, value, cellProperties)=>{}-

refConfig 更多参考

参数说明类型默认值
columnsKey获取参照选中对象的值,约定数组第一个为表格回写值array'refname','refcode'
rowKey拖拽修改值关联keyarray-
isThreeBar表格中是否出现三道杠iconbooleanfalse
columnsData表头数据array-
tableData表体数据array-
columnsData表头数据array-
treeData树参照数据array-

multiColumnSorting

参数说明类型默认值
initialConfig某些列初始排序状态object-
indicator是否显示排序顺序指示符(小箭头)booleantrue
sortEmptyCells是否空单元格应该参与排序booleantrue
headerAction是否单击标题应该对表进行排序booleantrue
compareFunctionFactory自定义比较函数(sortOrder, columnMeta)=>{}-

numericFormat

参数说明类型默认值
pattern数字模式 具体参考string-
culture货币处理 具体参考string-

fillHandle

参数说明类型默认值
autoInsertRow填充到最后一行是否自动添加行booleantrue
direction自动填充方向string 值为vertical horizontal'vertical'

csvConfig

参数说明类型默认值
filename将导出文件名stringCSV_[YYYY]-[MM]-[DD]
exportHiddenRows在导出的文件中包含隐藏的行booleantrue
exportHiddenColumns在导出的文件中包含隐藏列booleantrue
columnHeaders在导出的文件中包含列标题booleantrue
rowHeaders在导出的文件中包含行标题booleantrue
columnDelimiter列分隔符string','
rowDelimiter行分隔符string\r\n
range将导出到文件的单元格范围[]-
mimeType将导出文件类型string"text/csv"

获取表格里的数据

 getData = () => {
    // 获取数据
    this.child.getData((data) => {
      console.log('data', data);
    });
  };

表格添加行

  onInsertRowData = () => {
    // onInsertRowData(number,source)
    // number 插入行的位置,0 为行首,-1 为行尾
    // source 插入的行对象,
    this.child.onInsertRowData(); // 默认行首,空对象
  };

删除多选选中的行

 onDelRowCheck = () => {
     this.child.onDelRowCheck();
  };

获取验证通过后数据

  getData = (callback) => {
    this.child.getData((data) => {
      console.log('data', data);
    });
  };

获取多选选中的数据

 getCheckData = () => {
     const checkboxData = this.child.getCheckbox();
     console.log('checkboxData', checkboxData);
 };

获取被修改后的数据

  getUpdateData = () => {
    const updateData = this.child.getUpdateData();
    console.log('updateData', updateData);
  };

获取被格式化的数据

  getFormatData = () => {
    const formatData = this.child.getFormatData();
    console.log('formatData', formatData);
  };

获取新增加的数据

  getAddRowData = () => {
    const addRowDate = this.child.getAddRowData();
    console.log('addRowDate', addRowDate);
  };

获取删除的数据

  getDelRowData = () => {
    const delRowData = this.child.getDelRowData();
    console.log('delRowData', delRowData);
  };

获取通过鼠标选中的行

  getSelectData = () => {
   // rowList 鼠标选中的行数据
   // indexList 鼠标选中行数据的下标
    const {rowList,indexList} = this.child.getSelectData();
    console.log('selectData',rowList,indexList);
  };

删除通过鼠标选中的行

  onDelRowSelect = () => {
     // rowList 删除的行数据
     //  indexList 删除行数据的下标
    const {rowList,indexList} = this.child.onDelRowSelect();
    console.log('rowList,indexList', rowList,indexList);
  };

导出csv

  onDownCsv = () => {
    this.child.onExportCSV();
  };

导出模板

onExportHeader = () => {
  this.child.onExportHeader();
};

动态更新设置

 this.child.updateSettings({
      readOnly: false,
});

日期国际化

i18n: {
      previousMonth: 'Previous Month',
      nextMonth: 'Next Month',
      months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
      weekdays: ['日', '一', '二', '三', '四', '五', '六'],
      weekdaysShort: ['日', '一', '二', '三', '四', '五', '六']
      },

开发调试

$ npm install -g bee-tools
$ git clone https://github.com/tinper-acs/ac-hand-table
$ cd ac-hand-table
$ npm install
$ npm run dev
0.2.1

4 years ago

0.2.0

4 years ago

0.1.24

5 years ago

0.1.23

5 years ago

0.1.22

5 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.36

5 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.1

5 years ago