1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!--
* 单元格编辑器
* https://www.ag-grid.com/vue-data-grid/component-cell-editor/
-->
<script lang="ts">
import { ref, onMounted, defineComponent, nextTick } from 'vue';
export default defineComponent({
setup(props: any) {
const cellInputRef = ref<any>(null);
const inputValue = ref<any>(null);
onMounted(() => {
// 编辑开始后
// 获取输入框焦点
nextTick(() => {
inputValue.value = props.params.value;
cellInputRef.value.focus();
});
});
// 编辑完成后发送到网格的最终值
const getValue = () => {
return inputValue.value;
};
// 在编辑开始前被调用一次,
// 以便在编辑开始前给编辑一个取消编辑的机会。
const isCancelBeforeStart = () => {
return false;
};
// 编辑完成时调用一次(例如,如果按下 Enter)。
// 如果返回 true,则编辑的结果将被忽略。
const isCancelAfterEnd = () => {
return false;
};
return {
cellInputRef,
inputValue,
getValue,
isCancelBeforeStart,
isCancelAfterEnd,
};
},
});
</script>
<template>
<div>
<div>
<q-input dense square filled v-model="inputValue" ref="cellInputRef" />
</div>
</div>
</template>
<style lang="scss" scoped></style>