0.0.1 • Published 8 months ago

edit-cell-button v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

实时编辑表格

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>

参数

属性名描述属性类型是否必填默认值
propsArray[]
columns表格列配置(该属性里面的全部字段会直接绑定到el-table-column组件上)Array[]
custom-col-max-height自定义列展示的内容主体最大高度Number400
height表格组件的高度,当指定分页时实际表格的高度为传入的高度减去尾部分页组件的高度70px,否则此高度就是实际表格的高度String, Number-
select是否多选Boolean-
select-props勾选列的其它参数(详情参考el-table-column组件参数)Object-
index是否显示序号Boolean, Function-
index-props序号列的其它参数(详情参考el-table-column组件参数)Object-
custom-col是否开启自定义列设置Booleantrue
page是否开启分页Booleantrue
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