Giter Club home page Giter Club logo

ng-material-treetable's Introduction

Angular Material TreeTable Component

Build Status Licence semantic-release Npm

A simple, customisable, and easy to use Angular Material TreeTable component.

Gif Demo

Live Demo

StackBlitz Demo


Table of Contents

  1. Installation
  2. Data Format
  3. Options
  4. Events

Installation

Simply install the package through npm

npm i ng-material-treetable --save

Make sure you have the angular material packages installed

npm i @angular/material @angular/cdk @angular/animations --save

import the main module

import { TreetableModule } from 'ng-material-treetable';

@NgModule({
    ...
  imports: [
    ...
    TreetableModule
  ],
  ...
})
export class AppModule { }

and use the component in your template

<treetable [tree]="yourTreeDataStructure"></treetable>

Finally, make sure you import the required material icons font in your styles.css

@import url('https://fonts.googleapis.com/css?family=Roboto:400,700|Material+Icons');

Data Format

The tree object that's rendered by the component can either be a Node<T> or a Node<T>[] where Node<T> is the following interface

import { Node } from 'ng-material-treetable';

interface Node<T> {
  value: T;
  children: Node<T>[];
}

Here's a simple example.

{
  value: {
    name: 'Reports',
    owner: 'Eric',
    protected: true,
    backup: true
  },
  children: [
    {
      value: {
        name: 'Charts',
        owner: 'Stephanie',
        protected: false,
        backup: true
      },
      children: []
    },
    {
      value: {
        name: 'Sales',
        owner: 'Virginia',
        protected: false,
        backup: true
      },
      children: []
    },
    {
      value: {
        name: 'US',
        owner: 'Alison',
        protected: true,
        backup: false
      },
      children: [
        {
          value: {
            name: 'California',
            owner: 'Claire',
            protected: false,
            backup: false
          },
          children: []
        },
        {
          value: {
            name: 'Washington',
            owner: 'Colin',
            protected: false,
            backup: true
          },
          children: [
            {
              value: {
                name: 'Domestic',
                owner: 'Oliver',
                protected: true,
                backup: false
              },
              children: []
            },
            {
              value: {
                name: 'International',
                owner: 'Oliver',
                protected: true,
                backup: true
              },
              children: []
            }
          ]
        }
      ]
    }
  ]
}

Options

Work in Progress...

An option input property can be used to customise the component

import { Node, Options } from 'ng-material-treetable';

<treetable
  [tree]="yourTreeDataStructure"
  [options]="yourOptions">
</treetable>
Name Description Type Default
verticalSeparator If true, separates table columns with vertical lines. boolean true
capitalisedHeader If true, capitalise the first letter of each column header. boolean -
highlightRowOnHover If true, hovering the mouse over a row highlights its background. boolean true
customColumnOrder By default, the columns are ordered following the array generated by calling Object.keys() on the nodes of the tree object; this option can be used to specify a custom order. Note that customColumnOrder needs to be an array containing all the keys present in the node object. Array -
elevation Sets the elevation of the card element wrapping the tree component. number 5

customColumnOrder

Given a tree data type like

interface Person {
  name: string;
  age: number;
  married: boolean;
}

const tree: Node<Person> = ...

a custom column order can be specified with the following options object

const opts: Options<Person> = {
  customColumnOrder: ['married', 'age', 'name']
}

an incomplete or incorrect customColumnOrder value will result in an error

customColumnOrder: ['married', 'age'] // 'name' missing
customColumnOrder: ['married', 'age', 'name', 'surname'] // 'surname' is not a valid key

Events

Work in Progress...

Name Description Type
nodeClicked Whenever a node is expanded or collapsed, emits an event with the new status of the node Node<T>

nodeClicked

<treetable
  [tree]="yourTreeDataStructure"
  (nodeClicked)="logToggledNode($event)">
</treetable>

logToggledNode(node: Node<SomeNodeType>): void {
  console.log(node);
}

ng-material-treetable's People

Contributors

hallysonh avatar mlrv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng-material-treetable's Issues

Conflicting selector

Hi, great library!

You named your component as ng-treetable but I think it's a bad practice to use ng- prefix for custom components as they might clash with Angular components in the future.

Instead you should pick unique prefix for this library (maybe nmt- that stands for Ng-Material-Treetable?).

Unnecessary console.logs in formatElevation function

I've started using this plugin and it is perfect for my needs, however I've noticed excessive logging in the console, coming from what seems to be the formatEleveation function which has a console.log(this.options); call, which produces the excessive logging.

how can we customize column headers?

Column headers some times need to spell out, "fixedVersion" changes to "Fixedversion", we have a need to show custom column names example: "Fixed Version". Is it possible to support it?

Move BrowserModule from TreetableModule.

BrowserModule already been imported in AppModule so do not need to include it again in TreetableModule. Otherwise users will have an error says, "Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead."

An array of Node<T> as [tree] or allow to hide the headers.

Its me again :) Hope you don't mind
const taskTree: Node<Task>[] = [{... }, {... }, ...];
Would be great if your module allowed to plug in an array of Nodes or allow to hide its headers because there's currently no way to have several nodes at the root level (or maybe I'm wrong?)

example usecase:
obraz

fold method not working in angular v9.2.0

Hey, guys. I am using angular version v9.2.0 and "typescript": "~3.8.3" and "fp-ts": "^2.8.3" versions.I downloaded the code from this repository and placed the files in my local application.
I am facing the below errors in the tree.service.ts file.
image
and
image
The above _traverse and getNodeDepth are important methods ,without them-the tree will not come in the application.Can someone please help me on resolving these errors

Add code

Could you add this code to the project to facilitate the retrieval of information for deletion and editing?

in treetable.component.ts

@output() lineClick: Subject = new Subject();
onLineClick(line: T): T{
return line;
}

in treetable.component.html add (click)="onLineClick(element)"

mat-cell *matCellDef="let element" [ngClass]="{'vertical-separator': options.verticalSeparator}" (click)="onLineClick(element)"

result on click

image

Change suggestion

Would it be acceptable to make these changes?

In treetable.component.html
image

In treetable.component.scss
image

in treetable.component.ts
image

Result

image

Filter TreeTable by predicate

Hello @ALL,

i need urgently your help.. is there are any way to filter the data in the treetable like in the mat-table?

Best thanks and regards!

Custom cell templates

Hi all,
is there any way to modify the Header cell like e.g

<ng-container matColumnDef="name">
  <th mat-header-cell *matHeaderCellDef> Name </th>
  <td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>

Best regards

Custom cell templates

As the title suggests, it would be possible to put whatever content inside a cell. It is related to the customColumnOrder option if there was an option to add or define columns then it would be possible to create an "Action" column with buttons, or a checkbox column to act upon rows, select them, etc...

mat-table component from material.angular solves it as follows:

<table mat-table [dataSource]="someDataSource">
  <ng-container matColumnDef="actions"> // actions represent column name
      <td mat-cell *matCellDef="let element"> 
          <button (click)="doSomething(element.id)">DELETE</button>
      </td> 
      ...
  </ng-container>
  ...
  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
</table>

Angular 9 compatibility

Hey, guys. Can I use this npm-module with angular 9? Because for now there is an error "ERROR TypeError: Cannot redefine property: tree"

Refresh of data

I am trying to get this working in a component that is called from a set of search filters, which retrieves the data from a http call.
The first call sets the Node[] and the table data is displayed, but on subsequent calls to the component, the data is refreshed, but the table does not reload the new data.

Is this achievable?

Edit - I can see some work has been done on this in Fix #24

Tree not collapsing

I have the following structure in my project and the first ng-treetable is not collapsing I can collapse the second component no problem.
issue

As you can see I clicked on the second row but it didn't collapse these two tables are in a single component like so:

export class TasksComponent implements OnInit {
    chargeableTasks= taskTree;
    chargeableTasks2 = taskTree; // same object
    constructor() { }

    ngOnInit(): void { }
}
<mat-tab label="Chargeable">
        <div>
            <ng-treetable [tree]="chargeableTasks" id="xd">
            </ng-treetable>
        </div>
        <div>
            <ng-treetable [tree]="chargeableTasks2" id="xd2">
            </ng-treetable>
        </div>
</mat-tab>

So they reference the same object "taskTree" I imagine someone would need that for comparing two nodes of the same tree in split view or something.... Not sure if its a big issue since you can clone the object and be fine.

Add angular material dependencies

When installing the library on a fresh project generated by the angular-cli it errors out with Cannot find module '@angular/material'

Steps to reproduce:

  1. ng new project-name
  2. npm install ng-material-treetable
  3. Add TreeTableModule to AppModule
  4. ng serve and the project doesn't build because of the error

I know this library is material based (it even has it in the name), however I still think it would be good to add the dependencies, or at least add it to the installation guide, because there is the potential for confusion.

To be specific - all the angular material modules are needed - @angular/material @angular/cdk @angular/animations

Folder Structure of the Tree

Hello everybody, first of all a happy new year to all! To my question, correct me if I'm wrong, currently we can only create a tree view from one data type. This means only from one value type. Like we have a value of type A:

  • A
  • A
  • A

Is it possible or how can I best solve this that I can display a folder view. e.g.

  • A
    • Test1
    • Test2
    • A1
      -Test3
  • B
  • C

Something like that? Thank you very much it is a very nice development! and I would be very happy about the soon help!

Compatibility with Angular 9+

After upgrading Angular 7 to Angular 10 in my project, the treetable will not be rendered. The following error is displayed in the console:

image

I suspect that the cause is this import in treetable.component.ts, which is not updated:

image

Please see this thread.

Error

Can you help me with this error?
image

checkbox in mat-cell?

image
Hello everyone,
I want to insert checkbox in cell like above image. How do I do it? Thanks you.

Customize recursive node expansion

Currently when a node is clicked the sub tree rooted at that node is completely expanded. Would it be possible to make this customizable?

Support for on-demand or lazy loading of child nodes

First, thank you for this great component!

I wanted to ask your thoughts on support for lazy-loading child nodes - whether this can already be done, or any hints or directions if I found the time to implement it.

Serving up data for treetable via async obervable

Hi!
This component looks great, thank you. I'm currently having issues trying to serve data to the treetable using an observable stream. I know that this works with mat-table, should it also work with your treetable?

Thanks

James

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.