Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • René "Tiri" Dippe 5 posts 77 karma points
    Sep 13, 2018 @ 09:28
    René
    0

    How to Embed a grid layout inside a custom grid editor

    Hi there,

    I'm quite new to Umbraco (working with it for few month now) and have to create some custom modules for the Website/-shop of one of our customers.

    In the meanwhile that's easy the most time but the module I have to create currently is quite tricky. When I say "module" I mean grid editors, just to clarify the terminologies. I already looked through the board and asked google and ecosia for some help but didn't find anything. So I hope somebody here can help me.

    The module needs to enable the editors to create tabbed content. I already created the module so far that editors can create an extendable list (adding, removing and sorting the list elements), define tab-names and so on. But the tab contents need to use the same grid layout as the page itself.

    We have already defined a custom grid layout and its well used by the page template, but I'm stucked at nesting it to the tab-content.

    I tried with the following

    <div ng-controller="Umbraco.PropertyEditors.GridController" class="umb-grid umb-editor clearfix" id="umb-tab-grid">
        <div ng-grid="Umbraco.Grid"></div>
    </div>
    

    but it doesn't work, there's no grid showing up in the tab content area. What am I doin' wrong here or is there even a way to get what I want at all?

    My controllor looks the following:

    angular.module("umbraco")
    .controller("Umbraco.Tabs.ContentController",
        function ($scope, assetsService, $http, dialogService, mediaHelper) {
    
            $scope.defaultItem = {
                title: "",
                content: ""
            }
    
            $scope.add = function () {
                $scope.control.value.push(angular.copy($scope.defaultItem));
                $scope.select($scope.control.value[$scope.control.value.length - 1]);
            }
    
            $scope.select = function (index) {
                $scope.selected = index;
            };
    
            $scope.remove = function ($index, $event) {
                if ($scope.control.value.length > 1) {
                    $scope.control.value.splice($index, 1);
                }
                else {
                    $scope.control.value = [];
                }
                $scope.select($scope.control.value[$scope.control.value.length - 1]);
                $event.stopImmediatePropagation();
                $event.preventDefault();
            };
    
            $scope.sortableOptions = {
                handle: ".list-item-header",
                axis: "y",
                delay: 150,
                distance: 5
            };
    
            assetsService.loadCss(
                "/App_Plugins/Tabs/css/flex.css",
                "/App_Plugins/Tabs/css/form.css",
                "/App_Plugins/Tabs/css/tabs.css"
            );
            if (!$scope.control.value) {
                $scope.control.value = [];
                $scope.add();
            }
    
            if ($scope.control.value.length > 0) {
                $scope.select($scope.control.value[0]);
            }
        });
    

    In the editor.html:

    <div ng-app="app" ng-controller="Umbraco.Tabs.ContentController">
        <div class="editor flex-row">
            <div class="flex-xs-100" ui-sortable="sortableOptions" ng-model="control.value">
                <div class="list list-field" ng-class="{'open':selected === tab}" ng-repeat="tab in control.value track by $index">
                    <div class="list-item-header flex-row space between" ng-click="select(tab)" ng-model="tab.title">
                        <strong>{{tab.title ? tab.title : "\{\{Tab "+ ($index + 1) +"\}\}"}}</strong>
                        <button ng-if="$index > 0" ng-click="remove($index,$event)" class="icon icon-trash" style="background:none;border:none;"></button>
                    </div>
                    <div class="list-item-content form">
                        <div class="field">
                            <label for="title">Tab-Bezeichnung</label>
                            <input type="text" name="title" ng-model="tab.title" class="form-control" />
                        </div>
                        <div class="field">
                            <label for="content">Tab-Inhalt</label>
                            <div ng-controller="Umbraco.PropertyEditors.GridController" class="umb-grid umb-editor clearfix" id="umb-tab-grid">
                                <div ng-grid="Umbraco.Grid"><!--here is where the grid needs to go --> </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="cell-tools-add -bar newbtn" ng-click="add()">
            <i class="icon icon-add"></i>
        </div>
    </div>
    
  • René "Tiri" Dippe 5 posts 77 karma points
    Sep 17, 2018 @ 14:26
    René
    0

    Hi there,

    upset about the lag of answers to my question (especially because my question had to be read and confirmed by an admin because I'm new here) and due to my task's deadline I'm now using RTE as fallback, which is indeed exactly what I wanted to avoid.

    So now the editors have to be firm with writing HTML if they want to embed more complex content than some text into the tab areas, this is not any kind of solution but a crude fallback and exactly what Grid Layouts are made for to avoid.

    I'm still looking for a solution to enable a grid layout inside of the Tab-Contents of my custom grid editor. If I find something I'll post it here to support other umbraco users who might or might not have the same issue in the future.

    Kind regards

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Sep 17, 2018 @ 20:44
    Rune Hem Strand
    1

    Hi René,

    First of all, welcome to the Our forum!

    I understand your frustration with the lack of answers. It might be that your question is a little bit confusing. I, at least, find it hard to decipher what the end goal is here. Might just be me misunderstanding things 🤔

    If I understand your example correctly, you've created a custom grid editor. If created and registered correctly a grid editor will be select-able from the list of grid editors when clicking Add Content in a cell. Is this not the case?

    Then you state that you need to enable a grid layout inside your Tab-Contents grid editor? What exactly do you mean by that? Are you trying to nest Grid Layouts? Simply adding the controller for Grid Layouts is not enough. You will need to pass in the pre-values from a configured grid data type in order for it to render. Now, you might be doing that already but that is not obvious from the code sample.

    For creating tabbed content it might be worth looking in to Nested Content (which is a core property editor) or perhaps something like Stacked Content, depending on what you need. I think they will help you create a solution that is more maintainable.

    Hope that helps, if not, maybe you can provide some more context/explanation and that will lead to an answer you can use 😀

    All the best
    Rune

  • René "Tiri" Dippe 5 posts 77 karma points
    Sep 17, 2018 @ 21:21
    René
    1

    Hi Rune,

    okay I know what ye mean. I'll try to be more descriptive. First of all: thanks for your reply :)

    Yeah you're right, I created a new custom Grid Editor called "Tabs" and yes it shows up in the List of Grid Editors when I click on "Add Content" in the Grid Layout.Screenshot of how the editor looks like

    As you can see in the bottom area there's "Tab-Inhalt" which is currently an RTE. I'd like to get this to be the same Grid Layout as for where the Editor is in. Is it now more clear what I want to achieve? And I want to do this without using another package or plugin or any other third party stuff.

    Looking forward to your reply and hope it's more obvious what I want to do :)

    Kind regards Tiri

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Sep 18, 2018 @ 07:44
    Rune Hem Strand
    1

    That looks neat :)

    What errors do you get, if any when adding the grid?

    As mentioned above, you'll need to have a configuration (prevalues) for the grid on the model. You can see how the grid controller works and what it expects in the source code for the controller.

    Another issue you might run in to is that the controller tries get content from model.value and saves there as well. You'll need to take that in to account as well.

    I'm not saying it's an easy task - the core property editors are not built to be nested in that way ootb :) Might be worthwhile having a look at how Doc Type Grid editor works in the grid or Stacked Content / Inner Content which also wraps core property editors in a property editor.

  • René "Tiri" Dippe 5 posts 77 karma points
    Sep 18, 2018 @ 09:18
    René
    1

    Hi Rune,

    that's the point, I don't get any error messages. I tried to add the grid via

    <div ng-controller="Umbraco.PropertyEditors.GridController" class="umb-grid umb-editor clearfix">
        <div ng-grid="Umbraco.Grid"></div>
    </div>
    

    and hoped the Grid would show up in this container, but it didn't show up anything in the editor then (no grid, no error message, nothin' at all). I found that suggestion anywhere via Ecosia, but without any further information of what's necessary for this to work. And hoped someone here might know how to get this (or another solution) running.

    I'll have a look at the page you linked and in the source code of Nested Content package. Thanks for this :)

    Kind regards and thanks for your help so far :)

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Sep 18, 2018 @ 12:32
    Rune Hem Strand
    1

    There is no grid component, so you'll need the entire grid html file.

  • René "Tiri" Dippe 5 posts 77 karma points
    Sep 18, 2018 @ 13:57
    René
    0

    Okay, thanks.

    One last question: We're also using a custom Grid Layout DataType (Developer > Data Types ... > new data type > Property editor: Grid Layout) for Pages, does "using the entire grid html file" work for this as well?

    Kind regards Tiri

Please Sign in or register to post replies

Write your reply to:

Draft