1.3.71 • Published 4 years ago

antd-etable v1.3.71

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

Ant Design Editable Table

NPM Version NPM Downloads npm.io

image

Online Demo

https://guozhaolong.github.io/antd-etable/

Usage

import React, {useContext, useState} from "react";
import EditableTable from 'antd-etable';
import {Button} from 'antd';
import styles from './index.css';

const data = [
  {id:1,name:'测试1',title:'哈哈',status:0,desc:'描述1描述1描述1描述1',type:0,created_time:'2019-5-2'},
  {id:2,name:'测试2',title:'呵呵',status:1,desc:'描述2描述2描述2描述2',type:1,created_time:'2019-5-3'},
  {id:3,name:'测试3',title:'嘻嘻',status:2,desc:'描述3描述3描述3描述3',type:0,created_time:'2019-5-4'}
];
const type = ['类型一','类型二'];
const status = ['正常','异常','停止'];
const cols = [
  {
    title: '名称',
    dataIndex: 'name',
    editable:true,
    editor: {
      required: true,
    },
  },
  {
    title: '类型',
    dataIndex: 'type',
    editable:true,
    editor: {
      type: 'select',
      options: [
        {key: 1, value: '类型一'},
        {key: 2, value: '类型二'},
      ]
    },
    render: (text, record) => (
      type[text]
    ),
  },
  {
    title: '日期',
    dataIndex: 'created_time',
    editable:true,
    editor: {
      type: 'datetime'
    }
  },
];
const allCols = [
  ...cols.slice(0,2),
  {
    title: '标题',
    dataIndex: 'title',
    editable:true,
    width: 120,
  },
  ...cols.slice(2),
  {
    title: '状态',
    dataIndex: 'status',
    editable:true,
    width: 120,
    editor: {
      type: 'select',
      options: status.map((value,key) => ({key,value}))
    },
    render: (text, record) => (
      status[text]
    ),
  }
];
export default function() {
  const [changedData,setChangedData] = useState([]);
  const fetch = (pager,filter,sorter) => {
    // Do Remote Fetch
  };
  return (
    <div className={styles.root}>
      <div style={{textAlign:'right',marginBottom:16}}><Button type="primary">保存</Button></div>
      <EditableTable
        title=""
        loading={false}
        data={data}
        changedData={changedData}
        pageSize={10}
        total={100}
        cols={cols}
        allCols={allCols}
        onFetch={()=>fetch()}
        onChangedDataUpdate={(d)=>{setChangedData(d)}}
      />
    </div>
  );
}

API

EditableTable
属性
名称描述类型默认值
data初始化数据Array
changedData用于保存增删改的更新数据Array
cols表格列Array
allCols可显示表格列(格式同cols属性)Array
rowKey唯一标识String'id'
newRowKeyPrefix新增数据唯一标识的前缀String'new_'
title标题String或Component''
loading读取状态Booleanfalse
pageSize每页记录数Number10
total记录总数Number0
multiSelect可多选Booleanfalse
showHeader是否显示顶栏Booleantrue
showFooter是否显示底栏Booleantrue
showToolbar是否显示顶部工具栏Booleantrue
showSelector是否显示选择按钮Booleanfalse
showAddBtn是否显示添加按钮Booleantrue
showOpBtn是否显示编辑和删除按钮Booleantrue
showTopPager是否显示顶部分页器Booleantrue
showBottomPager是否显示底部分页器Booleanfalse
buttons自定义操作按钮组Component
style样式Objectnull
expandedRowRender展开行时的渲染内容ReactNodenull
expandedFirstRow默认展开第一行Booleanfalse
editOnSelected点击一行时编辑Booleanfalse
parentForm传入formFormInstancenull
事件
名称描述参数返回值
canEdit每行是否可编辑recordBoolean
canRemove每行是否可删除recordBoolean
beforeEdit编辑数据前触发
afterEdit编辑数据后触发
onAdd新增数据的默认对象Object
onFetch请求数据事件pager,filter,sorter
onChangedDataUpdate更新数据变化时触发arr
onSelectRow每页记录数rows
onDownload每页记录数filter,sorter
onExpandedRow展开一行时触发record
方法
名称描述参数返回值
resetTable重置表格页码

Config

changedData
数组,用于保存变更后的数据,每条数据中会使用isNew、isUpdate、isDelete来标识该数据是新增、更新还是删除
cols
参数例子
[{
   title: 'ID',
   dataIndex: 'id',
   editable:false,
},{
   title: '名称',
   dataIndex: 'name',
   sorter: true,
   editable:true,
   editor: {
     required: true,
     type: 'select',
     options: [
       {key: 1, value: '类型一'},
       {key: 2, value: '类型二'},
     ],
     validator: (rule,value,callback) => {
       if(data.find(d => d.name === value))
         callback('名称已存在!');
       else
         callback();
     },
   },
}]
editable:设置可编辑状态
editor:对象默认类型为text,支持的类型包括select、number、datetime、checkbox,如果为select需传入options参数
rowKey
数据的唯一标识,必须唯一,用于判断编辑状态和匹配数据
onAdd
当点击新增时,可配置初始化数据的方法用于返回一个新数据对象,可用来设置一些默认值
onChangedDataUpdate
每次新增、更新、删除都会触发该方法,并传入更新后的数组
onSelectRow
该方法会传入一个已选对象的数组,如果为单选模式,该数组只包含当前点击行的对象
onDownload
点击工具栏下载时触发,如果配置了方法,则该方法会接到filter和sorter两个参数,如果没有配置方法则默认生成当页的excel下载
1.3.71

4 years ago

1.3.70

4 years ago

1.3.69

4 years ago

1.3.68

4 years ago

1.3.67

4 years ago

1.3.66

4 years ago

1.3.65

4 years ago

1.3.64

4 years ago

1.3.63

4 years ago

1.3.61

4 years ago

1.3.62

4 years ago

1.3.59

4 years ago

1.3.60

4 years ago

1.3.57

4 years ago

1.3.58

4 years ago

1.3.56

4 years ago

1.3.54

4 years ago

1.3.55

4 years ago

1.3.53

4 years ago

1.3.52

4 years ago

1.3.51

4 years ago

1.3.50

4 years ago

1.3.49

4 years ago

1.3.48

4 years ago

1.3.47

4 years ago

1.3.46

4 years ago

1.3.45

4 years ago

1.3.44

4 years ago

1.3.42

4 years ago

1.3.43

4 years ago

1.3.41

4 years ago

1.3.40

4 years ago

1.3.39

4 years ago

1.3.36

4 years ago

1.3.37

4 years ago

1.3.38

4 years ago

1.3.35

4 years ago

1.3.33

4 years ago

1.3.34

4 years ago

1.3.32

4 years ago

1.3.31

4 years ago

1.3.30

4 years ago

1.3.29

4 years ago

1.3.28

4 years ago

1.3.27

4 years ago

1.3.26

4 years ago

1.3.25

4 years ago

1.3.24

4 years ago

1.3.23

4 years ago

1.3.22

4 years ago

1.3.21

4 years ago

1.3.20

4 years ago

1.3.19

4 years ago

1.3.18

4 years ago

1.3.17

4 years ago

1.3.16

4 years ago

1.3.15

4 years ago

1.3.14

4 years ago

1.3.13

4 years ago

1.3.12

4 years ago

1.3.10

4 years ago

1.3.11

4 years ago

1.3.9

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.11

4 years ago

1.2.10

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago