diff --git a/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue b/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue index 124be5a8..9055db11 100644 --- a/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue +++ b/io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue @@ -882,7 +882,7 @@ const buttonObj = reactive({ const expandFun = (arr, treeExpand) => { arr.forEach((item) => { if (props.tree && item.children && item.children.length > 0) { - item.expand = !treeExpand; + item[rowDataExtraPropertyName.expand] = !treeExpand; expandFun(item.children, treeExpand); } }); @@ -1379,7 +1379,7 @@ const rowDbClick = (evt, row, index) => { } else if (!Tools.isEmpty(row) && props.dbClickOperation === buttonObj.clone.name) { clone(row); } else if (!Tools.isEmpty(row) && props.dbClickOperation === buttonObj.expand.name) { - row['expand'] = Tools.isEmpty(row['expand']) ? true : !row['expand']; + row[rowDataExtraPropertyName.expand] = Tools.isEmpty(row[rowDataExtraPropertyName.expand]) ? true : !row[rowDataExtraPropertyName.expand]; } else { view(); } @@ -1505,6 +1505,19 @@ const requestHandler = async (ops) => { }); return resp; }; + +const expandDatas = []; +const extractExpandStatus = (arr) => { + arr.forEach((item) => { + if (item[rowDataExtraPropertyName.expand]) { + expandDatas.push(item[props.primaryKey]); + } + if (item.children?.length > 0) { + extractExpandStatus(item.children); + } + }); +}; + const onRequest = async (ops: any) => { state.loading = true; const resp: any = await requestHandler(ops); @@ -1525,6 +1538,10 @@ const onRequest = async (ops: any) => { table.rows = []; } } else if (resp && resp.data && props.tree) { + if (!table.treeExpand && table.rows.length > 0) { + expandDatas.splice(0, expandDatas.length); + extractExpandStatus(toRaw(table.rows)); + } const responseData = resp.data; if (Array.isArray(responseData)) { state.pagination.rowsNumber = responseData.length; @@ -1579,8 +1596,12 @@ const initRowDataExtraProperty = (rowData) => { rowData[rowDataExtraPropertyName.rowKey] = Tools.uuid(); rowData[rowDataExtraPropertyName.ticked] = rowData[rowDataExtraPropertyName.ticked] || false; rowData[rowDataExtraPropertyName.selected] = rowData[rowDataExtraPropertyName.selected] || false; - if (props.tree && Tools.isEmpty(rowData[rowDataExtraPropertyName.expand])) { - rowData[rowDataExtraPropertyName.expand] = false; + if (props.tree) { + if (expandDatas.length > 0 && expandDatas.includes(rowData[props.primaryKey])) { + rowData[rowDataExtraPropertyName.expand] = true; + } else if (Tools.isEmpty(rowData[rowDataExtraPropertyName.expand])) { + rowData[rowDataExtraPropertyName.expand] = false; + } } }; /**