UI builder with child collection
b
Does anyone know how to use
AddChildCollectionGroup()
and
AddChildCollection()
in Umbraco UI builder? I looked at the docs here: https://docs.umbraco.com/umbraco-ui-builder/v/13.ui-builder.latest-lts/collections/child-collections/child-collection-groups but I can't figure out how
StudentProjectController
is used/called: https://docs.umbraco.com/umbraco-ui-builder/v/13.ui-builder.latest-lts/collections/child-collections/retrieve-child-collections In my specific use-case I can list members (readonly) and want to map entities from a custom db table with logs/audits for a member using member. Is this possible?
j
Looks like it is the same as a regular collection, and that you can add a custom repository for the CRUD things. So something like this:
Copy code
csharp
builder.AddSection(
    "SectionName",
    sectionConfig =>
        sectionConfig.Tree(treeConfig =>
            treeConfig
                .AddCollection<ParentModel>(
                    x => x.ParentId,
                    "Parent",
                    "Parents",
                    "List of parents",
                    "icon-client",
                    "icon-client",
                    collectionConfig =>
                        collectionConfig
                            .SetRepositoryType<ParentUiRepository>()
                            .AddChildCollection<ChildModel>(
                                x => x.ChildId,
                                "Children",
                                "List of children",
                                "icon-client",
                                "icon-client",
                                childCollectionConfig =>
                                    childCollectionConfig 
                                        .SetRepositoryType<ChildUiRepository>()
                                        .SetNameProperty(x => x.Name)
b
I could fetch data using a custom repository. Not sure how the
AddChildCollection<T>()
should work with an existing table: https://docs.umbraco.com/umbraco-ui-builder/collections/child-collections/retrieve-child-collections#child-repositories I guess it requires adding a relation db table with parent/child id. It would be great if the model examples also had SQL query for the table creation.
j
If you have an existing table then you should be able to automatically connect by adding a model that corresponds to the structure of that table, and then including that model in the collection initialization: .AddChildCollection This example does it the other way around: https://docs.umbraco.com/umbraco-ui-builder/how-to-guides/creating-your-first-integration#set-up-the-database But if you have an existing table then it should work if you can just manually match the model. We always do custom repos though as we often need to join several tables and present it in a viewmodel for the UI Builder
b
To use child collection it seems it also need to add another table with relations. E.g. in my use-case I have a
UserId
column, which value is member id in Umbraco cmsMember table.
@Matt Brailsford does it require a relation table between the custom table and cmsMember table for instance? Or a custom repository, where I noticed parent id was passed into where clause in paged method.
6 Views