1.1.8 • Published 12 months ago

tarojs-table v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

tarojs-table

介绍

tarojs-table 是一个基于 Taro3.x 和 React18.x 封装的基础表格。

注意:这只是一个非常基础的表格组件,暂不支持合并行/列,展开行等功能,请谨慎选用。(所支持的功能请看属性配置

(温馨提示:此组件仅在微信小程序上运行调试过,并未在其他平台进行调试运行,无法保证在其他平台能正常使用。)

安装

npm install tarojs-table

使用

import { View } from '@tarojs/components';
import { useEffect, useState } from 'react';
import Table, { ColumnProps } from "tarojs-table";
// 内含 .css|.less|.scss 类型的样式文件,可自行选择引入
import "tarojs-table/lib/style.css";
// import 'tarojs-table/lib/style.less'
// import 'tarojs-table/lib/style.scss';

export default () => {
  const [loading, setLoading] = useState(false);
  const [dataSource, setDataSource] = useState<any[]>([]);

  useEffect(() => {
    // 模拟loading
    setLoading(true);

    setTimeout(() => {
      setLoading(false);
    }, 2000);

    setDataSource([
      { name: 'Margaret', gender: 'Female', age: 29, occupation: 'Financial Analyst', address: '789 Birch St' },
      { name: 'Michael', gender: 'Male', age: 42, occupation: 'Marketing Manager', address: '456 Pine Ave' },
      //{ ...其他数据 }
    ]);
  }, []);

  const columns: ColumnProps[] = [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      width: 50,
      fixed: 'left',
      align: 'center',
      render: (text: any, record: any, index: number) => index + 1
    },
    // {...其他列}
    {
      title: '操作',
      dataIndex: 'action',
      key: 'action',
      width: 80,
      fixed: 'right',
      align: 'center',
      className: 'action-cell',
      render: (text: any, record: any, index: number) => <View style={{ color: "blue" }}>编辑</View>
    }
  ];

  return (
    <Table
      loading={loading}
      columns={columns}
      dataSource={dataSource}
      scroll={{ y: '100vh', x: '100vw' }}
    />
  );
};

效果:

属性配置

TableProps

参数说明类型可选默认值
id表格 idstring
columns表格列ColumnProps[]
dataSource表格数据any[]
className类样式string
style内联样式object
wrapperClassName最外层的包裹容器类样式string
wrapperStyle最外层的包裹容器内联样式object
rowKey唯一标识string
loading加载中遮罩boolean 丨 LoadingProps
empty空数据时显示TableEmptyProps
scroll内容超出范围滚动{ x?: number 丨 string, y?: number 丨 string }
onRow行属性(record: any, index: number) => RowProps
onScroll滚动时触发Function
onScrollToLower滚动到底部/右边,会触发 scrolltolower 事件Function
onScrollToUpper滚动到顶部/左边,会触发 scrolltoupper 事件Function

ColumnProps

参数说明类型可选默认值
title列名React.ReactNode
key列唯一标识string
dataIndex列字段string
width列宽number
className类样式string
align内容水平位置'left' 丨 'center' 丨 'right'
fixed固定列(设置此项时须设置列宽)'left' 丨 'right'
ellipsis文本超出省略(默认 1 行省略,可指定多行省略)boolean 丨 number
sortable是否可排序boolean
sortOrder排序方式'ascend'丨'descend'
onSort自定义排序(order?: 'ascend'丨'descend') => void
render自定义渲染内容(value: any, record: any, index: number) => React.ReactNode

RowProps

参数说明类型可选默认值
className行样式string
style行内联样式object
onTap点击行Function

TableEmptyProps

参数说明类型可选默认值
img自定义图片(src)string
text自定义提示文字string

LoadingProps

参数说明类型可选默认值
show是否显示 Loadingboolean
img自定义 loading 图片(src)string
text自定义 loading 文字string
1.1.8

12 months ago

1.1.7

12 months ago

1.1.6

12 months ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

7 years ago