npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cgxqd/c-table

v1.0.5

Published

基于 `Element-UI` `Table` 组件封装的高阶表格组件,可无缝支持 element 的 table 组件。

Downloads

14

Readme

c-table

基于 Element-UI Table 组件封装的高阶表格组件,可无缝支持 element 的 table 组件。

安装

首先组件依赖 Element Table,先要安装 Element:

npm i element-ui

安装 c-table:

#npm
npm i @cgxqd/c-table
#yarn
yarn add @cgxqd/c-table

引入 Element、c-table

在 main.js 中写入以下内容:

<script>
    import Vue from 'vue';
    import ElementUI from 'element-ui';
    import CTable from '@cgxqd/c-table'
    import 'element-ui/lib/theme-chalk/index.css';
    import App from './App.vue';

    Vue.use(ElementUI);
    Vue.use(CTable)

    new Vue({
        el: '#app',
        render: h => h(App)
    });
</script>

使用

elementUI自带的属性方法,请参考elementUi文档

基础的表格

<template>
    <c-table :data="tableData" :config="tableConfig" :isLoading="false" @selection-change="handleSelectionChange"></c-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 弄'
                }],
                tableConfig: [
                    {type:'selection',width:60},
                    {label: '序号',type:'index',width:60},
                    {label: '日期',prop:'date'},
                    {label: '姓名',prop:'name'},
                    {label: '地址',prop:'address'},
                ]
            }
        },
        methods:{
            handleSelectionChange(v){},
        }   
    }
</script>

含有分页的表格

<template>
    <c-table :data="tableData" :config="tableConfig" has-pag :pagination="form" :init="init" ></c-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 弄'
                }],
                tableConfig: [
                    {label: '日期',prop:'date'},
                    {label: '姓名',prop:'name'},
                    {label: '地址',prop:'address'},
                ],
                form:{
                    page:1,     
                    pageSize:20,     
                    total:0,     
                }
            }
        },  
        methods:{
            init(){
                 //触发请求函数 
            },
        },
    }
</script>

多级表头

<template>
    <div>
        <c-table :data='tableData' :config='tableConfig'></c-table>
    </div>
</template>
<script>

    export default {
        data() {
            return {
                tableData: [{
                    date: '2016-05-03',
                    name: '王小虎',
                    province: '上海',
                    city: '普陀区',
                    address: '上海市普陀区金沙江路 1518 弄',
                    zip: 200333
                }, {
                    date: '2016-05-02',
                    name: '王小虎',
                    province: '上海',
                    city: '普陀区',
                    address: '上海市普陀区金沙江路 1518 弄',
                    zip: 200333
                }, {
                    date: '2016-05-04',
                    name: '王小虎',
                    province: '上海',
                    city: '普陀区',
                    address: '上海市普陀区金沙江路 1518 弄',
                    zip: 200333
                }, {
                    date: '2016-05-01',
                    name: '王小虎',
                    province: '上海',
                    city: '普陀区',
                    address: '上海市普陀区金沙江路 1518 弄',
                    zip: 200333
                }, {
                    date: '2016-05-08',
                    name: '王小虎',
                    province: '上海',
                    city: '普陀区',
                    address: '上海市普陀区金沙江路 1518 弄',
                    zip: 200333
                }, {
                    date: '2016-05-06',
                    name: '王小虎',
                    province: '上海',
                    city: '普陀区',
                    address: '上海市普陀区金沙江路 1518 弄',
                    zip: 200333
                }, {
                    date: '2016-05-07',
                    name: '王小虎',
                    province: '上海',
                    city: '普陀区',
                    address: '上海市普陀区金沙江路 1518 弄',
                    zip: 200333
                }],
                tableConfig: [
                    {label: '日期', prop: 'date'},
                    {
                        label: '配送信息', children: [
                            {label:'姓名',prop:'name'},
                            {label:'省份',prop:'province'},
                            {label:'市区',prop:'city'},
                            {label:'地址',prop:'address'},
                            {label:'邮编',prop:'zip'},
                        ]
                    }
                ],
            };
        },
    };
</script>

render渲染

    <script>
        export default {
            data(){
                return {
                    config:[
                        {label:'时间',prop:'time',render:this.filterTime},
                        {label:'金额',prop:'price',render:price=>`¥${price}`}
                        {label:'操作',render:<el-link type='primary'>编辑</el-link>},
                    ]
                }
            },
            methods:{
                filterTime(time,{row},h){
                    console.log(time);// 打印时间
                    console.log(row.time);// 打印时间
                    /**时间过滤 */
                    // return h('span',time);
                    return <span>{time}</span>
                }
            }       
        }   
    </script>

slot插槽

    <template>
        <div>
            <c-table :data='tableData' :config='tableConfig'>
                <template slot="filterTime" slot-scope="{row}">{{row.time}}</template>
            </c-table>
        </div>
    </template>
    <script>
        export default {
            data(){
                return {
                    tableData:[],
                    config:[
                        {label:'时间',slot:'filterTime'},
                    ]
                }
            },   
        }   
    </script>

isShow是否显示当前列

    <template>
        <div>
            <c-table :data='tableData' :config='tableConfig'></c-table>
        </div>
    </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 弄'
                    }],
                    tableConfig: [
                        {label: '日期',prop:'date'},
                        {label: '姓名',prop:'name'},
                        {label: '地址',prop:'address'},
                        {label: '地址',isShow:false,render:<el-link>删除</el-link>},
                    ],
                }
            },   
        }   
    </script>

c-table Methods

详细使用请参考 Element Table Methods

    <c-table ref='testRef' />
    // 调用方法 this.$refs.testRef.clearSelection()

c-table Attributes && c-table Events

以下属性为新增属性,其他具体的属性设置可以参考 Element Table AttributesTable Events文档

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ---- | ---- | ---- | ---- | ---- | | isLoading | 表格组件是否显示loading | Boolean | - | false | | align | 配置表格全局table-column的对齐方式 | String | left/center/right | center | | tableClassName | 给el-table 设置 className | String/Object/Array | - | - | | tableStyle | 给el-table 设置 style | String/Object/Array | - | - | | has-pag | 是否启动分页 | Boolean | - | false | | init | 触发分页的请求函数 | Function | - | - | | layout | 组件布局 子组件用逗号隔开 | String | - | total,sizes,prev,next,jumper | | pageSizes | 每页希纳是个数选择器的选项配置 | Array | - | [20, 50, 100, 150] | | pagination | 分页的配置信息 | Object | - | - | | config | 配置表格的el-table-column | Array | - | [] |

pagination

具体的属性设置可以参考 Element Pagination 文档

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ---- | ---- | ---- | ---- | ---- | | page | 当前页数 | Number | - | 1 | | page-size | 每页多少条个数 | Number | - | 20 | | total | 总条目数 | Number | - | - |

config

config 中每项的配置项其实就是 Element Table-column 上的 props 属性,具体的属性设置可以参考 Element Table-column 文档,以下为新增属性。

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ---- | ---- | ---- | ---- | ---- | | render | 渲染属性 | function(cellValue,{row,column,$index},h),HTMLElement,String,* | - | - | | slot | 插槽名 | String | - | - | | isShow | 当前列是否显示 | Boolean | - | true |