Ends in:
7 DAYS
23 HRS
11 MIN
56 SEC
Ends in:
7 D
23 H
11 M
56 S
Open Closed

tree #6645


User avatar
0
nabass created

hi sir, i have a big problem now i made a query and used jsTree to make tree view and it works good but it works for just one level what i mean is one parent has 2 child what if one of these child is parent for another child what should i do? i want to make a view like image 1 and this is my query which is working good but just for one level of parent like image 2 is ABP support this feature and has a documentation link to do that or not??

ALTER PROCEDURE [dbo].[GetAccountTreeStructure2] AS BEGIN SET NOCOUNT ON;

WITH RecursiveCTE AS (
    -- Anchor member: Select root nodes (accounts with no parent)
    SELECT
        A.Id,
        A.AccountName AS ChildName,
        A.ParentAccountId,
        A.AccountLevelId,
        AL.AccountLevelTitle AS ParentName,
        0 AS Level
    FROM
        Acc_Account A
    INNER JOIN
        Acc_AccountLevel AL ON A.AccountLevelId = AL.Id
    WHERE
        A.ParentAccountId IS  NULL 

    UNION ALL

    -- Recursive member: Select child nodes recursively
    SELECT
        A.Id,
        A.AccountName AS ChildName,
        A.ParentAccountId,
        A.AccountLevelId,
        AL.AccountLevelTitle AS ParentName,
        Level + 1 AS Level
    FROM
        Acc_Account A
    INNER JOIN
        Acc_AccountLevel AL ON A.AccountLevelId = AL.Id
    INNER JOIN
        RecursiveCTE R ON A.ParentAccountId = R.Id
)

-- Final query to retrieve the tree structure with account and level information
SELECT
    Id,
    ChildName,
    ParentAccountId,
    AccountLevelId,
    ParentName,
    Level  -- Include the Level column to display the level of each node
FROM
    RecursiveCTE;

END;

  • ABP Framework version: v8
  • UI Type: MVC
  • Database System: EF Core (SQL Server)

1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can consider using code.

    For example:

    A code : 00001 A.1 code : 00001.00001 A.2 code : 00001.00002 A.1.1 code 00001.00001.00001 B code 00002 B.1 code 00002.00001

    You can easily query all children through code.

    Here is a open source project you can check this: https://github.com/maliming/Owl.GeneralTree

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06