Skip to content

Commit c80ec8c

Browse files
author
m.ivanov4
committed
docs: add first sample documentation
1 parent d4bb63e commit c80ec8c

15 files changed

+146
-47
lines changed

projects/table-builder/README.md

-24
This file was deleted.

projects/table-builder/src/lib/table/components/table-thead/table-thead.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
[style.line-height.px]="clientRowHeight"
66
[@fadeAnimation]="'in'"
77
>
8-
<strong class="cell-nowrap">{{ key }}</strong>
8+
<strong class="cell-nowrap">{{ key | titlecase }}</strong>
99
</div>

projects/table-builder/src/lib/table/table-builder.component.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
<div class="table-grid__root" [ngDynamicHeight]="{ height: height }">
1+
<div *ngIf="source?.length" class="table-grid__root" [ngDynamicHeight]="{ autoHeight: autoHeight, height: height }">
22
<div
33
#tableViewport
4-
*ngIf="source?.length"
54
wheelThrottling
65
class="table-grid"
76
[style.width]="width"

projects/table-builder/src/lib/tests/simple-table.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('[TEST]: Simple table', () => {
3939
fixture.detectChanges();
4040
});
4141

42-
it('should create ngx-table', (done) => {
42+
it('should create ngx-table', (done: any) => {
4343
expect(component).toBeDefined();
4444
fixture.detectChanges();
4545

@@ -58,7 +58,7 @@ describe('[TEST]: Simple table', () => {
5858

5959
const actualColumnHtml: string = new HtmlFormatter(`
6060
<table-thead>
61-
<div class="table-grid__cell table-grid__header-cell"><strong class="cell-nowrap">id</strong></div>
61+
<div class="table-grid__cell table-grid__header-cell"><strong class="cell-nowrap">Id</strong></div>
6262
</table-thead>
6363
<table-tbody>
6464
<virtual-scroller class="vertical">

src/app/app-routing.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { RouterModule } from '@angular/router';
3+
import { IntroductionComponent } from './samples/introduction/introduction.component';
34

45
@NgModule({
56
imports: [
@@ -8,7 +9,7 @@ import { RouterModule } from '@angular/router';
89
{
910
path: '',
1011
pathMatch: 'full',
11-
redirectTo: 'samples'
12+
component: IntroductionComponent
1213
},
1314
{
1415
path: 'samples',

src/app/app.component.html

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
<mat-drawer-container class="dashboard">
22
<mat-drawer mode="side" class="dashboard__menu" opened>
3-
<mat-toolbar class="title">Table builder</mat-toolbar>
3+
<mat-toolbar class="title">
4+
<img class="logo" src="https://angular.io/assets/images/logos/angular/angular.svg" alt="angular" />
5+
<a routerLink="/">Table builder</a>
6+
</mat-toolbar>
47

58
<mat-list class="menu">
69
<mat-list-item class="menu__item">
7-
<a routerLink="samples/first">Simple table</a>
10+
<a routerLink="samples/guide">- <strong>Guide overview</strong></a>
11+
</mat-list-item>
12+
<mat-divider></mat-divider>
13+
<mat-list-item class="menu__item">
14+
<a routerLink="samples/first">- Example virtual scroll table</a>
815
</mat-list-item>
916
<mat-divider></mat-divider>
1017
</mat-list>

src/app/app.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { NgModule } from '@angular/core';
55
import { AppComponent } from './app.component';
66
import { SharedModule } from './shared/shared.module';
77
import { AppRoutingModule } from './app-routing.module';
8+
import { IntroductionComponent } from './samples/introduction/introduction.component';
89

910
@NgModule({
10-
declarations: [AppComponent],
11+
declarations: [AppComponent, IntroductionComponent],
1112
imports: [BrowserModule, SharedModule, AppRoutingModule, BrowserAnimationsModule],
1213
bootstrap: [AppComponent]
1314
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<div class="main__wrap">
2+
<h1>Angular Table Builder</h1>
3+
<p>
4+
The `ngx-table-builder` is an customizable data-table with a fully-templated API, dynamic columns, and an
5+
accessible DOM structure. This component acts as the core upon which anyone can build their own tailored
6+
data-table experience.
7+
</p>
8+
9+
<pre><code class="plaintext">
10+
$ npm install --save @angular-ru/table-builder
11+
</code></pre>
12+
13+
<p>
14+
After a few seconds of waiting, you should be good to go. Let's get to the actual coding! As a first step, let's
15+
add the Angular table builder module to our app module (src/app.module.ts):
16+
</p>
17+
18+
<pre><code class="typescript">
19+
import &#123; TableBuilder &#125; from '@angular-ru/table-builder';
20+
21+
@NgModule(&#123;
22+
imports: [ TableBuilder.forRoot() ],
23+
...
24+
&#125;)
25+
export class AppModule &#123; &#125;
26+
</code></pre>
27+
28+
<p>Next, let's declare the basic grid configuration. Edit src/app.component.ts:</p>
29+
30+
<pre><code class="typescript">
31+
import &#123; Component } from '@angular/core';
32+
33+
@Component(&#123;
34+
selector: 'app-root',
35+
template: `&lt;ngx-table-builder [source]="rowData"&gt;&lt;/ngx-table-builder&gt;`
36+
})
37+
export class AppComponent &#123;
38+
rowData = [
39+
&#123; make: 'Toyota', model: 'Celica', price: 35000 },
40+
&#123; make: 'Ford', model: 'Mondeo', price: 32000 },
41+
&#123; make: 'Porsche', model: 'Boxter', price: 72000 }
42+
];
43+
}
44+
</code></pre>
45+
46+
<ngx-table-builder [source]="rowData"></ngx-table-builder>
47+
48+
<p>
49+
For more information on the interface and a detailed look at how the table is implemented, see the
50+
<a routerLink="samples/guide">guide</a>.
51+
</p>
52+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { AfterViewInit, Component } from '@angular/core';
2+
import { TableRow } from '@angular-ru/table-builder';
3+
4+
declare const hljs: any;
5+
6+
@Component({
7+
selector: 'introduction',
8+
templateUrl: './introduction.component.html'
9+
})
10+
export class IntroductionComponent implements AfterViewInit {
11+
public rowData: TableRow[] = [
12+
{ make: 'Toyota', model: 'Celica', price: 35000 },
13+
{ make: 'Ford', model: 'Mondeo', price: 32000 },
14+
{ make: 'Porsche', model: 'Boxter', price: 72000 }
15+
];
16+
17+
public ngAfterViewInit(): void {
18+
document.querySelectorAll('pre code').forEach((block: any) => {
19+
hljs.highlightBlock(block);
20+
});
21+
}
22+
}

src/app/samples/sample-first/sample-first.component.css

Whitespace-only changes.

src/app/samples/sample-first/sample-first.component.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<mat-toolbar class="simple-toolbar">
2-
<span>Simple table ({{ simple?.length }}x{{ table?.columnKeys?.length }})</span>
2+
<span>Virtual scroll table ({{ simple?.length }}x{{ table?.columnKeys?.length }})</span>
33
<mat-spinner *ngIf="loading" class="spinner" strokeWidth="5" [diameter]="30"></mat-spinner>
44
</mat-toolbar>
55

@@ -52,6 +52,7 @@
5252
[source]="simple"
5353
[width]="width"
5454
[height]="height"
55+
[auto-height]="true"
5556
[row-height]="rowHeight"
5657
[column-width]="columnWidth"
5758
></ngx-table-builder>

src/app/samples/sample-first/sample-first.component.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { CodeDialogComponent } from '../../shared/dialog/code-dialog.component';
66
@Component({
77
selector: 'sample-first',
88
templateUrl: './sample-first.component.html',
9-
styleUrls: ['./sample-first.component.css'],
109
changeDetection: ChangeDetectionStrategy.OnPush
1110
})
1211
export class SampleFirstComponent implements OnInit {
@@ -28,10 +27,14 @@ export class SampleFirstComponent implements OnInit {
2827
this.dialog.open(CodeDialogComponent, {
2928
data: {
3029
title: 'Overview simple table (app.component.html)',
30+
description: 'If you want enabled virtual scroll, you need use auto-height or height attribute.',
3131
code:
3232
`<!-- simple - is Array any objects -->\n` +
33-
`<ngx-table-builder [source]="simple"></ngx-table-builder>\n\n` +
34-
`<!-- also you can set height, width for table -->\n` +
33+
`<ngx-table-builder\n` +
34+
` [source]="simple"\n` +
35+
` [auto-height]="true"\n` +
36+
`></ngx-table-builder>\n\n\n` +
37+
`<!-- also you can set height, width for cell in table -->\n` +
3538
`<ngx-table-builder\n` +
3639
` [source]="simple"\n` +
3740
` [width]="width"\n` +
@@ -40,7 +43,7 @@ export class SampleFirstComponent implements OnInit {
4043
` [column-width]="columnWidth"\n` +
4144
`></ngx-table-builder>\n`
4245
},
43-
height: '340px',
46+
height: '450px',
4447
width: '600px'
4548
});
4649
}
@@ -84,9 +87,9 @@ export class SampleFirstComponent implements OnInit {
8487

8588
const baseRow: TableRow = {
8689
id: idx,
87-
name: 'Hello - ' + ((Math.random() + 1) * 100).toFixed(0) + '__' + idx,
88-
description: 'World - ' + ((Math.random() + 1) * 100).toFixed(0) + '__' + idx,
89-
_id: '5cdae5b2ba0a57f709b72142' + '__' + idx,
90+
name: 'Random - ' + ((Math.random() + 1) * 100).toFixed(0) + '__' + idx,
91+
description: 'Random - ' + ((Math.random() + 1) * 100).toFixed(0) + '__' + idx,
92+
guid: '5cdae5b2ba0a57f709b72142' + '__' + idx,
9093
['About Big Text And More Powerful Label Fugiat tempor sunt nostrud']: `
9194
Fugiat tempor sunt nostrud ad fugiat. Laboris velit duis incididunt culpa consectetur veniam.
9295
Fugiat tempor sunt nostrud ad fugiat. Laboris velit duis incididunt culpa consectetur veniam.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<h3>{{ data.title }}</h3>
2+
<p *ngIf="data.description">{{data.description}}</p>
23
<pre><code class="html">{{ data.code }}</code></pre>
34

45
<button class="dialog-close" mat-button (click)="close()">OK</button>

src/app/shared/shared.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import { FormsModule } from '@angular/forms';
1818
import { ScrollingModule } from '@angular/cdk/scrolling';
1919
import { TableBuilderModule } from '@angular-ru/table-builder';
2020
import { CodeDialogComponent } from './dialog/code-dialog.component';
21+
import { CommonModule } from '@angular/common';
2122

2223
@NgModule({
23-
imports: [TableBuilderModule.forRoot(), MatButtonModule],
24+
imports: [TableBuilderModule.forRoot(), CommonModule, MatButtonModule],
2425
entryComponents: [CodeDialogComponent],
2526
declarations: [CodeDialogComponent],
2627
exports: [

src/styles.css

+40-5
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,42 @@ body {
88
font-family: Roboto, 'Helvetica Neue', sans-serif;
99
}
1010

11+
a {
12+
color: #000;
13+
}
14+
1115
.dashboard {
1216
height: 100%;
1317
}
1418

1519
.dashboard__menu {
16-
background: #0040a7;
20+
background: rgb(24, 75, 170);
1721
color: #fff;
18-
width: 250px;
22+
width: 280px;
1923
}
2024

2125
.title {
2226
background: transparent;
2327
color: #fff;
2428
}
2529

26-
.menu__item a {
30+
.dashboard__menu a {
2731
color: #fff;
2832
text-decoration: none;
2933
}
3034

3135
.dashboard__content.mat-drawer-content {
32-
padding: 10px 16px;
33-
height: calc(100% - 20px);
36+
padding: 0 100px;
37+
height: 100%;
3438
background: whitesmoke;
3539
}
3640

41+
.mat-drawer.mat-drawer-side {
42+
z-index: 2;
43+
box-shadow: 2px 0 5px 0 rgba(0, 0, 0, 0.6);
44+
border-right: none;
45+
}
46+
3747
.mat-toolbar.simple-toolbar {
3848
padding: 0;
3949
}
@@ -60,3 +70,28 @@ body {
6070
.dialog-close {
6171
float: right;
6272
}
73+
74+
.main__wrap {
75+
width: 1024px;
76+
margin: 0 auto;
77+
}
78+
79+
code {
80+
border: 1px dotted #c3c3c3;
81+
}
82+
83+
.logo {
84+
width: 30px;
85+
margin-right: 10px;
86+
margin-top: -3px;
87+
}
88+
89+
.mat-list-item-content a {
90+
padding-left: 5px;
91+
}
92+
93+
.mat-divider {
94+
border-top-color: rgba(241, 232, 232, 0.12);
95+
width: 80%;
96+
margin: 0 auto !important;
97+
}

0 commit comments

Comments
 (0)