@@ -80,12 +80,23 @@ const fullEdit = ref(false)
8080
8181const tableRef = ref (null )
8282const fieldFilterOption = ref (null )
83+ const findValueIndexByKey = (fieldKey ) => {
84+ if (! (props .value instanceof Array )) {
85+ return - 1
86+ }
87+ return props .value .findIndex ((item ) => item .k === fieldKey)
88+ }
8389const fieldColumn = computed (() => ({
8490 key: ' key' ,
8591 title : () => i18n .t (' common.field' ),
8692 align: props .textAlign !== TextAlignType .Left ? ' center' : ' left' ,
8793 titleAlign: ' center' ,
8894 resizable: true ,
95+ sorter : (row1 , row2 ) =>
96+ ` ${ row1? .k || ' ' }` .localeCompare(` ${row2? .k || ' ' }` , undefined, {
97+ numeric: true,
98+ sensitivity: 'base',
99+ }),
89100 ellipsis: {
90101 tooltip: {
91102 style: {
@@ -167,7 +178,8 @@ const startEdit = async (no, key, value) => {
167178
168179const saveEdit = async (field, value, decode, format) => {
169180 try {
170- const row = props .value [currentEditRow .no - 1 ]
181+ const rowIndex = findValueIndexByKey(currentEditRow.key)
182+ const row = rowIndex >= 0 ? props.value[rowIndex] : null
171183 if (row == null) {
172184 throw new Error('row not exists')
173185 }
@@ -187,9 +199,10 @@ const saveEdit = async (field, value, decode, format) => {
187199 format,
188200 retDecode: props.decode,
189201 retFormat: props.format,
190- index: [ currentEditRow . no - 1 ] ,
202+ index: rowIndex >= 0 ? [rowIndex] : undefined ,
191203 })
192204 if (success) {
205+ currentEditRow.key = field
193206 currentEditRow.value = value
194207 $message.success(i18n.t('interface.save_value_succ'))
195208 } else {
@@ -233,12 +246,18 @@ const actionColumn = {
233246 format: props.format,
234247 })
235248 if (success) {
236- delete props .value [index][' rm' ]
249+ const rowIndex = findValueIndexByKey(row.k)
250+ if (rowIndex >= 0) {
251+ delete props.value[rowIndex]['rm']
252+ }
237253 $message.success(i18n.t('dialogue.reload_succ'))
238254 } else {
239255 // update fail, the key may have been deleted
240256 $message.error(msg)
241- props .value [index][' rm' ] = true
257+ const rowIndex = findValueIndexByKey(row.k)
258+ if (rowIndex >= 0) {
259+ props.value[rowIndex]['rm'] = true
260+ }
242261 }
243262 },
244263 onCopy: async () => {
@@ -256,7 +275,10 @@ const actionColumn = {
256275 reload: false,
257276 })
258277 if (success) {
259- props .value .splice (index, 1 )
278+ const rowIndex = findValueIndexByKey(row.k)
279+ if (rowIndex >= 0) {
280+ props.value.splice(rowIndex, 1)
281+ }
260282 $message.success(i18n.t('dialogue.delete.success', { key: row.k }))
261283 } else {
262284 $message.error(msg)
0 commit comments