File

C:/GoDev/src/TCSTK-Angular/projects/tibco-tcstk/tc-core-lib/src/lib/components/tibco-cloud-table/tibco-cloud-table.component.ts

Implements

OnInit OnChanges

Metadata

selector tc-tibco-cloud-table
styleUrls ./tibco-cloud-table.component.css
templateUrl ./tibco-cloud-table.component.html

Index

Properties
Methods
Inputs

Inputs

jsonSource
Type : string

Methods

camelCaseTW
camelCaseTW(header: string | any)
Parameters :
Name Type Optional
header string | any No
Returns : any
ngOnChanges
ngOnChanges(changes)
Parameters :
Name Optional
changes No
Returns : void
ngOnInit
ngOnInit()
Returns : void
updateTable
updateTable()
Returns : void

Properties

columns
Type : []
Default value : []
dataSource
Type : TibcoCloudTableDataSource
displayedColumns
Type : []
Default value : []

Columns displayed in the table. Columns IDs can be added, removed, or reordered.

id
Type : string
Default value : '_' + Math.random().toString(36).substr(2, 9)
paginator
Type : MatPaginator
Decorators :
@ViewChild(MatPaginator, {static: true})
sort
Type : MatSort
Decorators :
@ViewChild(MatSort, {static: true})
import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { TibcoCloudTableDataSource } from './tibco-cloud-table-datasource';
import { TcCoreCommonFunctions } from '../../common/tc-core-common-functions';

@Component({
  selector: 'tc-tibco-cloud-table',
  templateUrl: './tibco-cloud-table.component.html',
  styleUrls: ['./tibco-cloud-table.component.css']
})
export class TibcoCloudTableComponent implements OnInit, OnChanges {
  @Input() jsonSource: string;
  @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
  @ViewChild(MatSort, { static: true }) sort: MatSort;

  dataSource: TibcoCloudTableDataSource;

  id: string = '_' + Math.random().toString(36).substr(2, 9);

  /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
  displayedColumns = [];
  columns = [];

  ngOnInit() {
    this.updateTable();


  }
  ngOnChanges(changes) {
    console.log('Table Changed');
    this.updateTable();

  }


  updateTable() {
    // console.log('JSONSource: ', this.jsonSource);
    const parsedJsonSource = JSON.parse(this.jsonSource);
    // console.log('Parsed JSON Source: ', parsedJsonSource);
    this.dataSource = new TibcoCloudTableDataSource(this.paginator, this.sort, parsedJsonSource);
    const myColumns = [];
    if (parsedJsonSource.length != null) {
      if (parsedJsonSource.length > 0) {
        // console.log(parsedJsonSource[0]);
        if (parsedJsonSource[0] != null) {
          const myColumns = [];
          let m = 0;
          for (const headerName in parsedJsonSource[0]) {
            if (parsedJsonSource[0].hasOwnProperty(headerName)) {
              // console.log(m + ' headerName:', headerName);
              this.displayedColumns.push(headerName);
              myColumns[m] = {};
              myColumns[m]['columnDef'] = headerName;
              myColumns[m]['header'] = headerName;
              myColumns[m].cell = function (element) {
                return `${element[headerName]}`;
              };
              this.columns = myColumns;
            }
            m++;
          }
        }
        // console.log('myColums:', this.columns);
        // this.columDefArray = this.columns;
      }
    }
  }


  /*
  private log(...m){
    console.log('TIBCO CLOUD TABLE] ' , m);
  }*/

  camelCaseTW(header: string | any) {

    return TcCoreCommonFunctions.camelCaseToWords(header);


  }
}
<div class="mat-elevation-z8">
  <table id="{{id}}" mat-table class="tct-full-width-table" [dataSource]="dataSource" matSort aria-label="Elements">
    <ng-container *ngFor="let column of columns" [matColumnDef]='column.columnDef'>
      <mat-header-cell *matHeaderCellDef class="tct-header"  mat-sort-header>{{camelCaseTW(column.header)}}</mat-header-cell>
      <mat-cell *matCellDef="let row">{{ column.cell(row) }}</mat-cell>
    </ng-container>
    <mat-header-row *matHeaderRowDef="displayedColumns"  ></mat-header-row>
    <mat-row *matRowDef="let row; columns: displayedColumns;
                         let even = even;
                         columns: displayedColumns;"
             [ngClass]="{gray: even}"></mat-row>
  </table>
  <mat-paginator [ngClass]="{'tct-hide': dataSource.data.length < 10}" #paginator
                 [length]="dataSource.data.length"
                 [pageIndex]="0"
                 [pageSize]="10"
                 [pageSizeOptions]="[5, 10, 20, 25]">
  </mat-paginator>
</div>

./tibco-cloud-table.component.css

.tct-full-width-table {
  width: 100%;
}
.tct-header{
  /*
  background-color: #d0d5e2;
  font-size: 16px;
*/
  background: #0081cb;
  color:white;
  padding:5px 30px;
  display:flex;
  align-items: center;
}

.tct-header:hover{
  background-color: #229be0;
}

.tctgray {
  background-color: #f5f5f5;
}

.tct-hide{
  display: none;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""