GithubHelp home page GithubHelp logo

femessage / el-data-table Goto Github PK

View Code? Open in Web Editor NEW
487.0 19.0 114.0 12.8 MB

🥘Base on element-ui, makes crud easily

Home Page: https://femessage.github.io/el-data-table/

License: MIT License

JavaScript 31.22% Vue 66.60% Shell 2.18%
element-ui table crud restapi

el-data-table's Introduction

el-data-table

Build Status NPM Download NPM Version NPM License PRs Welcome Automated Release Notes by gren

Auto requesting by axios, supports pagination, tree data structure, custom search, custom operation column, which makes rest api easily👏

The table uses @femessage/el-form-renderer to render form.

中文文档

Table of Contents

Introduction

CRUD

el-data-table is created to solve business problems, so CRUD logic is set inside.
For example, to develop user api, suppose its relative path like this:

/api/v1/users

The restful CRUD api should be:

  • Retrieve
GET /api/v1/users?page=1&size=10

default data structure

{
  "code":0,
  "msg":"ok",
  "payload":{
    "content":[], // dataPath
    "totalElements":2, // totalPath
  }
}

You can customize dataPath/totalPath.

If hasPagination=false, default dataPath is payload

  • Create
POST / api / v1 / users
  • Update
PUT /api/v1/users/:id
  • Delete
DELETE /api/v1/users/:id

Then only need to use the following code to complete CRUD functions

<template>
  <el-data-table v-bind="tableConfig"></el-data-table>
</template>
<script>
export default {
  data() {
    return {
      tableConfig: {
        url: '/example/users',
        columns: [
          {
            prop: 'name',
            label: '用户名'
          }
        ],
        searchForm: [
          {
            type: 'input',
            id: 'name',
            label: '用户名',
            el: {
              placeholder: '请输入'
            }
          }
        ],
        form: [
          {
            type: 'input',
            id: 'name',
            label: '用户名',
            el: {
              placeholder: '请输入'
            },
            rules: [
              {
                required: true,
                message: '请输入用户名',
                trigger: 'blur'
              }
            ]
          }
        ]
      }
    }
  }
}
</script>

The results are as follows:

  • Retrieve

  • Create

  • Update

  • Delete

⬆Back to Top

Data Driven

Moving the content of the template to the script means that the template can be reduced and js can be extracted to another file to reuse. At the same time, the data in js is actually a piece of json, this means code generation tool can help.



9.jpeg

⬆Back to Top

Why

Why do you create el-data-table based on el-table of element-ui?

I often hear the following sounds:

  1. el-table can cover most scenarios without extended requirements
  2. wrap up so many things, it's heavy and high coupling
  3. bound with too many business logic, it's not flexible; business logic should handle by developers

First of all, I have to say, el-table is really flexible, but when implementing paging requests, only el-table is not enough, and the el-pagination component needs to be combined. Most of the content of paging processing is repeated. Without a high level business component, we get duplicate code everywhere.

In fact, in the admin or dashboard web app, there are many CRUD operations, using restful API. It is possible to use only one url to make a component to complete CRUD functions.

Secondly, many experienced developers think that components are the more flexible the better.

However, for the "newbees" who lack of experience, they are not familiar with common business scenarios. Some basic operations, like form validation, space filtering, adding loading, exception handling, they may forget, which result in bugs.

For front-line business developers, in the face of endless developing task, in fact, they don't want to deal with repeated business logic. they just want to free their hands and get off work early.

In such situation, el-data-table was born.

⬆Back to Top

Feature

  • Use configuration to call restful api to complete CRUD functions
  • Support table display tree structure data
  • Bound with pagination logic
  • Support custom column buttons, and custom operation functions
  • Support saving query on url, which can resotre search status after history.go(-1) or location.reload()

⬆Back to Top

Links

⬆ Back to Top

Install

Encourage using Yarn to install

yarn add @femessage/el-data-table

⬆Back to Top

Quick Start

Global Register Component

This is for minification reason: in this way building your app, webpack or other bundler just bundle the dependencies into one vendor for all pages which using this component, instead of one vendor for one page

import Vue from 'vue'
// register component and loading directive
import ElDataTable from '@femessage/el-data-table'
import ElFormRenderer from '@femessage/el-form-renderer'
import {
  Button,
  Dialog,
  Form,
  FormItem,
  Loading,
  Pagination,
  Table,
  TableColumn,
  Message,
  MessageBox
} from 'element-ui'
Vue.use(Button)
Vue.use(Dialog)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Loading.directive)
Vue.use(Pagination)
Vue.use(Table)
Vue.use(TableColumn)
Vue.component('el-form-renderer', ElFormRenderer)
Vue.component('el-data-table', ElDataTable)
// to show confirm before delete
Vue.prototype.$confirm = MessageBox.confirm
// show tips
Vue.prototype.$message = Message
// if the table component cannot access `this.$axios`, it cannot send request
import axios from 'axios'
Vue.prototype.$axios = axios

Template

<template>
  <el-data-table></el-data-table>
</template>

⬆Back to Top

Reference

⬆Back to Top

Contributing

For those who are interested in contributing to this project, such as:

  • report a bug
  • request new feature
  • fix a bug
  • implement a new feature

Please refer to our contributing guide.

⬆ Back to Top

Contributors

Thanks goes to these wonderful people (emoji key):


levy

💻 👀 📖 🚇 🤔

Donald Shen

💻 ⚠️ 📖

MiffyCooper

💻 📖

Huanfeng Chen

💻

EVILLT

💻 🐛

Alvin

💻 🐛

Han

💻 🐛 📖

kunzhijia

💻 🔧 💡

Edgar

💻 🐛

Barretem

💻

阿禹。

📖

lujunwei

💻

cjf

🐛 💻

Jack-rainbow

🐛

ColMugX

💻

snowlocked

💻 📖

Sponge

🐛 💻

4Ark

💻 📖

Htongbing

💻

PPPenny

💻

PopupDialog

🐛

Jogiter

💻

yolofit

🐛

huazaili

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT

⬆Back to Top

el-data-table's People

Contributors

2nthony avatar allcontributors[bot] avatar alvin-liu avatar chenedgar avatar cjfff avatar colmugx avatar dbraum avatar dependabot-preview[bot] avatar dependabot[bot] avatar donaldshen avatar eviiit avatar garyhjy avatar gd4ark avatar huazaili avatar levy9527 avatar lianghx-319 avatar longyue9608 avatar lujunwei avatar miffycooper avatar ouzuyu avatar prisbre avatar shoyuf avatar snowlocked avatar tangofe avatar tanshiqi avatar xrr2016 avatar yolofit avatar zcqno1 avatar zenghao1203 avatar zhn4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

el-data-table's Issues

[TODO] 期望能在headerButtons后增加插槽,部分ui设计可能会用到一些滑块或其他非按钮元素

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

查询优化

我开始加载页面的时候不想去调接口 点击查询的时候去调接口 现在没有点击查询单独的方法或者查询 重置按钮不是默认存在 我可以自定义自己的按钮 自己的方法

增加设置form表单对齐参数

Uploading 1544686692(1).png…
formData 表单的样式并不对其,比如我有套餐名称四个字,我还有状态两个,这种字数不通导致有长有短,换行后更是不对其,可不是增加参数设置label宽度

pagination & i18n

Version

1.1.1

OS/Browsers version

Windows 10 - Chrome 73

Vue version

2.5.17

Questions

  1. pagination: When using pagination, suppose there are 25 pieces of data, set 20/page, all data is displayed on the first page, and when the second page is clicked, there are also 25 pieces. See the document and online example page without seeing relevant explanations and solutions.
  2. i18n: How to internationalize the operation buttons for search form and table.
    reproduce

What is Expected?

Maybe provide solutions and demo.

Error: TypeError: Cannot read property 'bindings' of null

环境: node 8.11.3
mac mojave 10.14.3
操作: clone 项目后 进入项目 yarn 到最后一步一直waiting,所以npm install
然后执行 npm run doc 报warning。 然后按照提示路径访问就是空白了。所以看不到文档

terminal_1
terminal_2
browser

增加新增、删除等按钮灵活性

期望:可以通过传prop的方式自定义按钮的文字,如新增按钮默认是”新增“,可以修改为”创建“

�场景:新增功能满足需求,但按钮文字描述不满足。
虽然可以通过ref引用调用内部onDefaultNew方法实现,但希望能支持自定义文字,少写几行代码

记录当前每个页码勾选的表格项

has PR #90

来自同事

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

期望有个开关 store-checked 之类的打开此功能

Additional context

例如第一页勾选了一些

image

切换到第二页勾选了一条

image

再切换回第一页, 依然会勾选之前勾选的

image

新增问题

我点击新增或是编辑按钮后,
怎么窗口在后,蒙层在前?顺序不对啊?

About the row of the table

We can select a row of data; but cant select single row. For another, we cant select a row of data by click the other zone of the row except the checkbox;

form 没有详细配置介绍

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

beforeConfirm

beforeConfirm里面可以考虑添加一个loading

新建或者编辑的一个错误处理

Is your feature request related to a problem? Please describe.
现在有这么一个场景,就是比如一个新建的场景,使用了 el-data-table 中的 form 功能,然后根据 crudc 去进行一个 post 请求,但是由于一些原因,后端判断这个名字重复,这个 post 请求没有成功,但也没有任何的提示,只是默默的失败了,

ps: 后端失败现在只给出了一个 resetful code 不为 0, 不是 http status code, 全局拦截不好做。

Describe the solution you'd like
我希望有一个可以传入错误处理的方式,比如我传入一个 onError 或者一个 onSucessCallBack 方法去处理操作失败的问题。

Additional context
提供后端 response 格式。
image

重置搜索框内容时,url携带多余参数

Describe the bug
重置搜索框内容时,url携带多余参数&

environment information
OS /浏览器版本
win10 / chrome 74

vue(Version)
2.5.17

el-data-table(Version)
1.1.1

Screenshots
el-data-table(reset重置携带多余参数)

Expected behavior
重置搜索框内容时,url不携带多余参数&

不传入url 仅传入列表数据做展示用

问题:

项目中会遇到 从另一个表格中筛选出数据进行展示的需求
image

这些数据是不需要请求的,这时再用el-data-table就不太合适了
尝试过直接访问 this.$refs.table.data 去直接修改数据源,但感觉不太合适

期望:

可以新增一个方法 直接更新列表数据
或者新增一个配置 可以填入列表数据

自定义列模板

这个element 本身有的功能被封装了,但是没有暴露,有需求要自定义列的样式,只能用formatter做简单样式

extraButtons中atClick中的的代码阻塞时,页面上的按钮都变成加载中

微信截图_20190424114805

1. 代码75行,await的目的是想通过res结果,来判断是否return Promise.resolve(true),以此控制是否需要刷新列表。 2.当75行代码阻塞,页面上所有按钮都变成加载状态(如图)

期望: atClick中代码阻塞时,页面上“仅当前点击的按钮”变成禁用状态,是否更为合理。

在已有条件下也有解决方法:
atClick代码非阻塞、return Promise.resolve(false)、手动刷新列表。
(不过建议在组件内部优化这个机制是否更为合理)

改变查看按钮颜色

现在的查看按钮是灰色的 我的需求是蓝色 所有希望可以增加改变查看按钮颜色的属性

在有el-data-table的list页面中,进入edit页面,需要发起两次动作($router.push('edit'))

Describe the bug
在有el-data-table的list页面中,点击新增按钮(this.$router.push({path: 'edit'}))。
1.第一次点击新增按钮后,在url路径中,在#前多加了一个多余的‘?’号,并且仍然在list页面未跳转
(路径示例:http://localhost:3000/?#/activity/assisting-activity/list)
2.第二次点击这个新增按钮,页面才跳转至edit页面(此时路径示例:http://localhost:3000/?#/activity/assisting-activity/edit)

Screenshots
first-tesee1
image

Expected behavior
1.点击一次即可跳转;
2.url 去掉未知的?号

**environment information: **
bug版本 1.2.1;
之前使用1.1.1版本,无此问题

分页里面的 mock 接口bug

我看了一下源码,对分页条数的数组是有支持自定义的,传了一个 :paginationSizes="pageArr" pageArr = [1,5,10] 选了每页 1 条,接口请求的时候参数也传了 size:1, 结果返回 3条数据。
一点建议:从组件的通用性,建议去掉 默认的修改按钮,让用户之间传需要使用的按钮就行了

文档完善(英文版)

文档少了个说明。
另外,文档还要补充的有:
selection,
delete按钮
等一系列属性的示例

tree型table拖拽和普通table拖拽

期待的功能
表格拖拽(tree型table拖拽/普通table拖拽)

OS /浏览器版本
win10 / chrome 74

Vue版本
2.5.17

为什么提出功能需求?
希望特定场景满足tree型table拖拽和普通table拖拽

考虑及目前做法

  1. 考虑过iview-admin、D2-admin、element-ui及data-table 实现tree拖拽,结果以失败告终。失败原因:以上组件都是同级渲染DOM结构,而sortTable是拖拽时获取拖拽子节点的父节点,因为DOM元素是同级渲染,所以我找不到一个table所有行的不同点来取出拖拽行下的所有子节点(当然不排除我写法错误)。

  2. 目前的做法,采用了递归VueDraggable组件,但我认为这不是最优的解决方案。

期望结果
tree型table及普通table拖拽,如果可以留言发表下实现tree型多级拖拽table思路那么就太完美了。Thank~~

可供参考组件

Vue.Draggable
组件拖拽demo
Nested draggable

【功能问题】如何添加 el-table 自带的事件

你好,我已经使用了你们的组件做好了数据渲染,都挺好的。

现在想使用el-table自带的事件row-click事件做点击行的处理,发现无法传递到table组件。
你们提供了一个tableAttrs是传递数据的,那请问事件如何传递过去?

我觉得使用表格自带的一些事件应该是基础需求,考虑扩展一下,或者把el-table自带的事件加上去?

按钮文字根据状态改变

extraButtons,配置项里面,可以设置:text字段接收多种方式吗?比如接收一个方法,执行方法,而不是让方法变成字符串显示在页面上

搜索表单默认提交行为

Describe the bug
组件 mounted 的时候会检查搜否有渲染 searchForm, 有的话就会添加组件表单默认行为的语句 **searchForm.$el.setAttribute('action', 'javascript:;'),由于我使用的场景下是动态渲染此搜索表单的,所以这个语句并没有生效, 导致按搜索按钮表单默认行为触发, url 改变页面刷新。

Screenshots
image

Expected behavior
searchForm 动态渲染的场景下,按下搜索不触发表单默认行为

**environment information: **

  • Version [v1.1.1]
  • OS: [windows]
  • Browser [chrome]

feat: 定制操作列按钮

Why

组件使用者有定制操作列样式的需求。一般是通过插入自定义列然后调用内部方法(如onDefaultEdit)的方式。但内部方法有可能在重构中被变更造成无意的破坏性更新。

How

  1. 建议标记onDefaultEdit之类的方法为public,显式出现在文档中;
  2. 或者,增加3个props,可以覆盖定制操作列三个按钮的所有属性

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.