TreeList üzerinde Expand ve Collapse özelliği

This commit is contained in:
Sedat Öztürk 2025-11-08 03:16:55 +03:00
parent 950fbf2a41
commit 50fe2907d1
3 changed files with 82 additions and 15 deletions

View file

@ -5203,6 +5203,18 @@
"en": "Recursive Selection", "en": "Recursive Selection",
"tr": "Özyinelemeli Seçim" "tr": "Özyinelemeli Seçim"
}, },
{
"resourceName": "Platform",
"key": "ListForms.ListFormEdit.CollapseAll",
"en": "Collapse All",
"tr": "Tümünü Daralt"
},
{
"resourceName": "Platform",
"key": "ListForms.ListFormEdit.ExpandAll",
"en": "Expand All",
"tr": "Tümünü Genişlet"
},
{ {
"resourceName": "Platform", "resourceName": "Platform",
"key": "ListForms.ListFormEdit.AutoExpandAll", "key": "ListForms.ListFormEdit.AutoExpandAll",

View file

@ -109,6 +109,8 @@ const Tree = (props: TreeProps) => {
getSelectedRowKeys, getSelectedRowKeys,
getSelectedRowsData, getSelectedRowsData,
refreshData, refreshData,
expandAll,
collapseAll,
getFilter, getFilter,
}) })
@ -154,6 +156,26 @@ const Tree = (props: TreeProps) => {
return tree.getSelectedRowsData() return tree.getSelectedRowsData()
} }
function expandAll() {
const tree = gridRef.current?.instance
if (!tree) return
tree.forEachNode((node: any) => {
if (node.hasChildren) {
tree.expandRow(node.key)
}
})
}
function collapseAll() {
const tree = gridRef.current?.instance
if (!tree) return
tree.forEachNode((node: any) => {
if (node.hasChildren) {
tree.collapseRow(node.key)
}
})
}
function refreshData() { function refreshData() {
gridRef.current?.instance.refresh() gridRef.current?.instance.refresh()
} }
@ -645,7 +667,9 @@ const Tree = (props: TreeProps) => {
setExtraFilters={setExtraFilters} setExtraFilters={setExtraFilters}
/> />
</Template> </Template>
<Toolbar visible={(toolbarData?.length ?? 0) > 0 || (filterToolbarData?.length ?? 0) > 0}> <Toolbar
visible={(toolbarData?.length ?? 0) > 0 || (filterToolbarData?.length ?? 0) > 0}
>
{toolbarData?.map((item) => ( {toolbarData?.map((item) => (
<Item key={item.name} {...item}></Item> <Item key={item.name} {...item}></Item>
))} ))}
@ -672,20 +696,21 @@ const Tree = (props: TreeProps) => {
mode={gridDto.gridOptions.selectionDto?.mode} mode={gridDto.gridOptions.selectionDto?.mode}
recursive={gridDto.gridOptions.treeOptionDto?.recursiveSelection || false} recursive={gridDto.gridOptions.treeOptionDto?.recursiveSelection || false}
></Selection> ></Selection>
<Paging <Paging enabled={true} defaultPageSize={gridDto.gridOptions.pageSize ?? 10} />
enabled={true}
defaultPageSize={gridDto.gridOptions.pagerOptionDto?.allowedPageSizes
?.split(',')
.map((a: any) => +a)?.[0] ?? 20}
/>
<Pager <Pager
visible={gridDto.gridOptions.pagerOptionDto?.visible ?? true} visible={gridDto.gridOptions.pagerOptionDto?.visible ?? true}
allowedPageSizes={gridDto.gridOptions.pagerOptionDto?.allowedPageSizes allowedPageSizes={
?.split(',') gridDto.gridOptions.pagerOptionDto?.allowedPageSizes
.map((a: any) => +a) ?? [10, 20, 50, 100]} ?.split(',')
showPageSizeSelector={gridDto.gridOptions.pagerOptionDto?.showPageSizeSelector ?? true} .map((a: any) => +a) ?? [10, 20, 50, 100]
}
showPageSizeSelector={
gridDto.gridOptions.pagerOptionDto?.showPageSizeSelector ?? true
}
showInfo={gridDto.gridOptions.pagerOptionDto?.showInfo ?? true} showInfo={gridDto.gridOptions.pagerOptionDto?.showInfo ?? true}
showNavigationButtons={gridDto.gridOptions.pagerOptionDto?.showNavigationButtons ?? true} showNavigationButtons={
gridDto.gridOptions.pagerOptionDto?.showNavigationButtons ?? true
}
infoText={gridDto.gridOptions.pagerOptionDto?.infoText} infoText={gridDto.gridOptions.pagerOptionDto?.infoText}
displayMode={gridDto.gridOptions.pagerOptionDto?.displayMode ?? 'full'} displayMode={gridDto.gridOptions.pagerOptionDto?.displayMode ?? 'full'}
></Pager> ></Pager>
@ -696,7 +721,7 @@ const Tree = (props: TreeProps) => {
<ColumnFixing <ColumnFixing
enabled={gridDto.gridOptions.columnOptionDto?.columnFixingEnabled} enabled={gridDto.gridOptions.columnOptionDto?.columnFixingEnabled}
></ColumnFixing> ></ColumnFixing>
<Scrolling <Scrolling
mode="virtual" mode="virtual"
rowRenderingMode="virtual" rowRenderingMode="virtual"
showScrollbar="always" showScrollbar="always"

View file

@ -24,6 +24,8 @@ const useToolbar = ({
getSelectedRowsData, getSelectedRowsData,
refreshData, refreshData,
getFilter, getFilter,
expandAll,
collapseAll,
}: { }: {
gridDto?: GridDto gridDto?: GridDto
listFormCode: string listFormCode: string
@ -31,6 +33,8 @@ const useToolbar = ({
getSelectedRowsData: () => any getSelectedRowsData: () => any
refreshData: () => void refreshData: () => void
getFilter: () => void getFilter: () => void
expandAll?: () => void
collapseAll?: () => void
}): { }): {
toolbarData: ToolbarItem[] toolbarData: ToolbarItem[]
toolbarModalData: ToolbarModalData | undefined toolbarModalData: ToolbarModalData | undefined
@ -54,7 +58,7 @@ const useToolbar = ({
return return
} }
// Add searchPanel // Add searchPanel
if (grdOpt.searchPanelDto?.visible) { if (grdOpt.searchPanelDto?.visible) {
items.push({ items.push({
locateInMenu: 'auto', locateInMenu: 'auto',
@ -62,7 +66,7 @@ const useToolbar = ({
name: 'searchPanel', name: 'searchPanel',
}) })
} }
items.push({ items.push({
widget: 'dxButton', widget: 'dxButton',
name: 'refreshButton', name: 'refreshButton',
@ -74,6 +78,32 @@ const useToolbar = ({
location: 'after', location: 'after',
}) })
// Add Expand All button for TreeList
if (gridDto?.gridOptions.layoutDto.defaultLayout === 'tree') {
items.push({
widget: 'dxButton',
name: 'expandAllButton',
options: {
icon: 'plus',
text: translate('::ListForms.ListFormEdit.ExpandAll'),
onClick: expandAll,
},
location: 'after',
})
// Add Collapse All button for TreeList
items.push({
widget: 'dxButton',
name: 'collapseAllButton',
options: {
icon: 'minus',
text: translate('::ListForms.ListFormEdit.CollapseAll'),
onClick: collapseAll,
},
location: 'after',
})
}
// field chooser panel // field chooser panel
if (grdOpt.columnOptionDto?.columnChooserEnabled) { if (grdOpt.columnOptionDto?.columnChooserEnabled) {
items.push({ items.push({