0.0.1 • Published 8 months ago
edit-cell-button v0.0.1
实时编辑表格
demo演示
:::demo
<template>
<div>
<!-- 文本 -->
<el-checkbox v-model="isCanEmpty">
开启文本空校验
</el-checkbox>
<el-checkbox v-model="isEditAble" @change="handleTableCellFocus">
文本框聚焦并选中
</el-checkbox>
<div style="display:flex;margin-top:10px">
<div>
<edit-cell-button
style="width:260px;"
type="input"
ref="text"
:isCanEmpty="isCanEmpty"
:value.sync="textValue"
:editable="true"
@input="(e) => updateCell(e)"
>
</edit-cell-button>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
selectValue:1,
isCanEmpty: false,
isEditAble: true,
checked: false,
textValue: '纯文本',
options: [
{
value: 0,
label: "选择框值1"
},
{
value: 1,
label: "选择框值2"
},
{
value: 3,
label: "选择框值3"
}
],
};
},
mounted(){
},
methods: {
updateCell(e){
console.log(e)
},
// 聚焦选中的方法
handleTableCellFocus(e){
if(e){
if(this.$refs.text && (typeof this.$refs.text.focusAndSelected) === 'function'){
this.$refs.text.focusAndSelected();
}
}
}
},
};
</script>
:::
## 依赖
- Vue 2.0.0+
- ElementUI
## 示例
- 安装
```code
npm i edit-cell -S --registry http://10.246.196.12:4873/
HTML部分
<div> <!-- 文本 --> <div style="display:flex;margin-top:10px"> <div> <edit-cell style="width:260px;" type="input" ref="text" :isCanEmpty="isCanEmpty" :value.sync="textValue" :editable="true" @input="(e) => updateCell(e)" > </edit-cell> </div> <div style="margin-left:10px"> <edit-cell style="height: 100%;width:300px" type="select" filterable :options="options" :value.sync="selectValue" :editable="true" @change="(e) => updateCell(e)" > </edit-cell> </div> </div> </div>
JS部分
<script> import CellEdit from 'cell-edit' export default { components: { CellEdit, }, data() { return { selectValue: 1, isCanEmpty: false, isEditAble: true, textValue: '纯文本', options: [ { value: 0, label: "选择框值1" }, { value: 1, label: "选择框值2" }, { value: 3, label: "选择框值3" } ], }; }, mounted(){ }, methods: { updateCell(e){ console.log(e) }, // 聚焦选中的方法 handleTableCellFocus(e){ if(e){ if(this.$refs.text && (typeof this.$refs.text.focusAndSelected) === 'function'){ this.$refs.text.focusAndSelected(); } } } }, } </script>
参数
属性名 | 描述 | 属性类型 | 是否必填 | 默认值 |
---|---|---|---|---|
props | Array | 否 | [] | |
columns | 表格列配置(该属性里面的全部字段会直接绑定到el-table-column组件上) | Array | 否 | [] |
custom-col-max-height | 自定义列展示的内容主体最大高度 | Number | 否 | 400 |
height | 表格组件的高度,当指定分页时实际表格的高度为传入的高度减去尾部分页组件的高度70px,否则此高度就是实际表格的高度 | String, Number | 否 | - |
select | 是否多选 | Boolean | 否 | - |
select-props | 勾选列的其它参数(详情参考el-table-column组件参数) | Object | 否 | - |
index | 是否显示序号 | Boolean, Function | 否 | - |
index-props | 序号列的其它参数(详情参考el-table-column组件参数) | Object | 否 | - |
custom-col | 是否开启自定义列设置 | Boolean | 否 | true |
page | 是否开启分页 | Boolean | 否 | true |
page-position | 分页组件的布局方式 | String(center或者right) | 否 | center |
page-props | 分页组件的其它参数(详情请参考 el-pagination 组件属性(注:不需要指定 current-page、page-size、total、disabled 属性,因为里面已经集成了这些属性)) | Object | 否 | - |
request | 获取表格数据的函数(返回值必须是Promise函数,并且里面得把总数total给resolve出去) | Function | 否 | - |
soon | 是否立即执行一次request方法 | Boolean | 否 | - |
expand | 展开行的其它参数(详情参考el-table-column组件参数) | Object | 否 | - |
show-tooltip | 当内容过长被隐藏时显示tooltip(默认添加到所有的列当中,所以指定了该参数可不在columns里面对应列当中指定原始的show-overflow-tooltip字段) | Boolean | 否 | - |
方法:
0.0.1
8 months ago