Create a sleek and innovative tree user interface in a single line with the power of Angular and fxF

I created a tree with parent and child nodes, but I'm facing an issue where the positions of the checkboxes are not aligned in a straight line. Here is my code snippet:

           
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
    <div>
        <button mat-icon-button disabled></button>
        <td fxFlex="150px" fxLayoutAlign="start">
            {{node.title}}
        </td> 
        <td fxFlex="100px" fxLayoutAlign="center">
            <mat-checkbox [(ngModel)]="node.can_view"></mat-checkbox>
        </td> 
        <td fxFlex="100px" fxLayoutAlign="center">
            <mat-checkbox [(ngModel)]="node.can_insert"></mat-checkbox>
        </td>
        <td fxFlex="100px" fxLayoutAlign="center">
            <mat-checkbox [(ngModel)]="node.can_update"></mat-checkbox>
        </td>
        <td fxFlex="100px" fxLayoutAlign="center">
            <mat-checkbox [(ngModel)]="node.can_delete"></mat-checkbox>
        </td>
        <td fxFlex="100px" fxLayoutAlign="center">
            <mat-checkbox [(ngModel)]="node.can_export"></mat-checkbox>
        </td> 
        <td fxFlex="100px" fxLayoutAlign="center">
            <mat-checkbox [(ngModel)]="node.can_upload"></mat-checkbox>
        </td>
        <td fxFlex="130px" fxLayoutAlign="center">
            <mat-checkbox [(ngModel)]="node.need_approve"></mat-checkbox>
        </td>
    </div>
</mat-tree-node>
<mat-nested-tree-node *matTreeNodeDef="let node; when: hasChild">

    <div class="mat-tree-node">
        <button mat-icon-button matTreeNodeToggle>
            <mat-icon>
                {{tc.isExpanded(node) ? 'keyboard_arrow_down' : 'chevron_right'}}
            </mat-icon>
        </button>
        <tr >
            <td fxFlex="150px" fxLayoutAlign="start">
                {{node.title}}
          </td> 
          <td fxFlex="100px" fxLayoutAlign="center">
              <mat-checkbox [(ngModel)]="node.can_view" (change)="update('can_view',node.id,$event.checked)" ></mat-checkbox>
          </td> 
          <td fxFlex="100px" fxLayoutAlign="center">
              <mat-checkbox [(ngModel)]="node.can_insert" (change)="update('can_insert',node.id,$event.checked)"></mat-checkbox>
          </td>
          <td fxFlex="100px" fxLayoutAlign="center">
              <mat-checkbox [(ngModel)]="node.can_update" (change)="update('can_update',node.id,$event.checked)"></mat-checkbox>
          </td>
          <td fxFlex="100px" fxLayoutAlign="center">
              <mat-checkbox [(ngModel)]="node.can_delete" (change)="update('can_delete',node.id,$event.checked)"></mat-checkbox>
          </td>
          <td fxFlex="100px" fxLayoutAlign="center">
              <mat-checkbox [(ngModel)]="node.can_export" (change)="update('can_export',node.id,$event.checked)"></mat-checkbox>
          </td> 
          <td fxFlex="100px" fxLayoutAlign="center">
              <mat-checkbox [(ngModel)]="node.can_upload" (change)="update('can_upload',node.id,$event.checked)"></mat-checkbox>
          </td>
          <td fxFlex="130px" fxLayoutAlign="center">
              <mat-checkbox [(ngModel)]="node.need_approve" (change)="update('need_approve',node.id,$event.checked)"></mat-checkbox>
          </td>     
      </tr>
    </div>
    <div style="margin-left:1em" [hidden]="!tc.isExpanded(node)">
        <ng-container matTreeNodeOutlet></ng-container>
    </div>
</mat-nested-tree-node>
</mat-tree>
</tbody>

In my project, I have implemented a tree structure with parent-child relationships, but I am looking to align the checkboxes in a single line.

Answer №1

The solution you're seeking is right here: MatTreeNodePadding. This handy feature allows you to set the padding for each level using matTreeNodePaddingIndent. By default, it follows the material design menu sub-menu specifications with a 40px indent.

To implement this, simply include it in your mat-tree-node as shown below:

<mat-tree-node ... matTreeNodePadding matTreeNodePaddingIndent="0">
 ...
</mat-tree-node>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Automatically populate the checkbox with the specified URL

Is it possible to pre-fill a checkbox in an HTML form using the URL? For example, if we have a URL like www.example.com/?itemname=sth Would there be a similar method to pre-select a checkbox via the URL? <ul class="list-group"> <li c ...

Developing interconnected dropdowns in Angular 8 for input fields

Imagine we have a list of names structured like this: nameSelected: string; names: Name[ {firstName: 'John', middleName: 'Danny', lastName: 'Smith'}, {firstName: 'Bob', middleName: 'Chris', lastN ...

Steer your keyboard attention towards the parent element that embodies a list

My implementation focuses on making drop down menus accessible via keyboard input using HTML/CSS and JS/jQuery events. The goal of keyboard accessibility includes: Tab key to navigate the menu elements. Pressing the down arrow key opens a focused menu. ...

Determining when a message has been ignored using php

One of the features I am working on for my app is adding announcements, which are essentially personalized messages to users. Once a user receives a message and dismisses it, I want to ensure that specific message does not appear again. Here is the PHP co ...

Trigger Vue method when the size of a div element changes

Is there a way to trigger a method every time the dimensions (width or height) of a div element change? <template> <div> </div> </template> <script> export default { methods: { updateSize() { // ...

TypeScript code runs smoothly on local environment, however encounters issues when deployed to production

<div> <div style="text-align:center"> <button class="btnClass">{{ submitButtonCaption }}</button> <button type="button" style="margin-left:15px;" class="cancelButton" (click)="clearSearch()"> {{ clearButtonCapt ...

Utilize CSS Steps to incorporate the initial position

I'm experimenting with CSS steps to create a unique visual effect resembling a "light board". The setup involves a column of 18 divs acting as individual "bulbs", with an animation that positions a div behind each one to simulate a "lit up bulb." The ...

Managing selected ticket IDs in a table with AngularJS

I have a table that includes options for navigating to the next and previous pages using corresponding buttons. When I trigger actions for moving to the previous or next page (via controller methods), I store the IDs of checked tickets in an array $scope. ...

What is the best way to send an enum from a parent component to a child component in

I'm trying to send an enum from a parent component to a child component. This is the enum in question: export enum Status { A = 'A', B = 'B', C = 'C' } Here's the child component code snippet: @Component({ ...

unable to interpret information

I've encountered an issue with posting data to my webpage (page3.php). Despite using $test=$_POST['radio_second']; on the page, the test variable remains empty. Any help in resolving this would be greatly appreciated. Thank you! <p> ...

Is there a way to retrieve a CSS file using AJAX from a separate origin?

Whenever I am trying to load a CSS file via AJAX from my dreamhost account, I encounter the error message that says No 'Access-Control-Allow-Origin' header is present on the requested resource. After searching for solutions online, I stumbled upo ...

Preventing Redundancy in Angular 2: Tips for Avoiding Duplicate Methods

Is there a way I can streamline my if/else statement to avoid code repetition in my header component? Take a look at the example below: export class HeaderMainComponent { logoAlt = 'We Craft beautiful websites'; // Logo alt and title texts @Vie ...

Extract the color of an individual character

There is a code snippet in JavaScript using p5.js that functions as a video filter: const density = ' .:░▒▓█' //const density = ' .tiITesgESG' //let geist; let video let asciiDiv let playing = false let ...

Animate a box moving continuously from the right to the left using jQuery

I'm trying to create a continuous motion where a box moves right, then left, and repeats the cycle. However, I can only get it to complete one cycle. $(document).ready(function() { function moveBox() { $('#foo').css({ 'ri ...

The request for XMLHttpRequest has been restricted from accessing ASP.NET CORE 2.2.0 with Angular 8 and signalr1.0.0 due to a failure in the CORS policy (Access-Control-Allow-Origin)

nugetPackage on .net core2.2.0: signalr 1.0.0 + ASP.Core2.2.0 I am utilizing angular to utilize signalr: package.json: "@aspnet/signalr": "1.1.0", my front-end Angular code: import { Component } from '@angular/core'; import * as signalR fro ...

Angular Typescript filter function returning an empty arrayIn an Angular project, a

I have a filtering function in Angular that is returning an empty array. Despite trying similar solutions from previous questions, the issue persists. The function itself appears to be correct. Any assistance would be greatly appreciated. gifts represents ...

Saving the subtracted value from a span into a cookie until the checkbox is unchecked - here's how to

I am working on a piece of code that includes numeric values within a span. When the checkbox is clicked, it subtracts 1 from the main value, essentially reducing the total value. How can I achieve this so that even after the form is submitted, the deducte ...

JavaScript problem with hovering action causing additional buttons to appear

Currently, I am developing a user interface where, upon hovering over an LI element, 2 buttons appear to provide additional functionality - "edit" and "remove". However, I am facing challenges with the mouse hit zones. The mouseover function works effect ...

CSS techniques for positioning a header image

I'm having an issue with using a banner I created in CS6 Illustrator as a header on my website. Despite setting it as the background, positioned at the top and set to "no-repeat", it keeps appearing at the bottom of the header area with around 300px o ...

"Reposition all elements contained within a div that have a specific class

I'm completely new to Javascript and I've been trying to move all elements with a specific class inside a particular div. After doing some research, I found a solution that worked using IDs. However, when I tried to adapt it to work with classNam ...