Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved some examples to new /examples route #213

Merged
merged 7 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions demo/src/app/components/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component, OnInit, Input } from '@angular/core';

@Component({
selector: 'header-component',
templateUrl: 'header.html'
})
export class HeaderComponent {

@Input() tagline: string = '';
}
9 changes: 9 additions & 0 deletions demo/src/app/components/header/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<section class="page-header internal">
<h1 class="project-name"><a routerLink="/">ng2-smart-table</a></h1>
<h2 class="project-tagline">{{ tagline }}</h2>

<a routerLinkActive="active" routerLink="/demo" class="btn">Quick Start</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write routerLink="demo" and etc. without slash.

<a routerLinkActive="active" routerLink="/examples" class="btn">Examples</a>
<a routerLinkActive="active" routerLink="/documentation" class="btn">Documentation</a>
<a target="_blank" href="https://github.com/akveo/ng2-smart-table" class="btn">View on GitHub</a>
</section>
1 change: 1 addition & 0 deletions demo/src/app/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './header/header.component';
11 changes: 0 additions & 11 deletions demo/src/app/pages/demo/demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import 'style-loader!./demo.scss';
})
export class DemoComponent {

sidebarScrolled = false;
sidebarOffset = 0;

snippets = {
install: require('raw-loader!./snippets/install.md'),
require: require('raw-loader!./snippets/require.md'),
Expand All @@ -23,14 +20,6 @@ export class DemoComponent {
array: require('raw-loader!./snippets/array.md'),
dataTemplate: require('raw-loader!./snippets/data-template.md'),
basicFull: require('raw-loader!./snippets/basic-full.md'),
sourceRequire: require('raw-loader!./snippets/source-require.md'),
createSource: require('raw-loader!./snippets/create-source.md'),
sourceTemplate: require('raw-loader!./snippets/source-template.md'),
search: require('raw-loader!./snippets/search.md'),
searchTable: require('raw-loader!./snippets/search-table.md'),
sourceFull: require('raw-loader!./snippets/source-full.md'),
hideFilters: require('raw-loader!./snippets/hide-filters.md'),
customEditorModule: require('raw-loader!./snippets/custom-editor-module.md'),
};

constructor() {
Expand Down
163 changes: 2 additions & 161 deletions demo/src/app/pages/demo/demo.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
<section class="page-header internal" id="top">
<h1 class="project-name"><a [routerLink]="['']">ng2-smart-table</a></h1>
<h2 class="project-tagline">Quick Start & Demos</h2>

<a routerLinkActive="active" routerLink="/demo" class="btn">Quick Start & Demos</a>
<a routerLinkActive="active" routerLink="/documentation" class="btn">Documentation</a>
<a target="_blank" href="https://github.com/akveo/ng2-smart-table" class="btn">View on GitHub</a>
</section>
<section class="main-content with-sidebar">
<nav class="fixed-sidebar" scrollPosition [maxHeight]="295" (scrollChange)="sidebarScrolled = $event.scrolled;" [ngClass]="{scrolled: sidebarScrolled}">
<h4>Navigation</h4>
<ul>
<li class="back-top"><a href="#top">&#8592; Back to Top</a></li>
<li>
<a href="#getting-started">Getting Started</a>

<ul>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li>
<a href="#examples">Examples</a>

<ul>
<li><a href="#minimal-setup">Minimal Setup Example</a></li>
<li><a href="#separate-filter">Standalone Filter Example</a></li>
<li><a href="#from-server">Loading From Server Example</a></li>
<li><a href="#confirm">Confirm Action Example</a></li>
<li><a href="#server">Load From Server Example</a></li>
<li><a href="#types">Completer and other built-in editors</a></li>
<li><a href="#custom-editor-renderer">Using a custom editor or renderer</a></li>
<li><a href="#multiselect">Multi select</a></li>
<li><a href="#filters">Completer and other built-in filters</a></li>
</ul>
</li>
</ul>
</nav>
<header-component [tagline]="'Quick Start & Demo'"></header-component>
<section class="main-content">

<h2 ><a id="getting-started" class="anchor" href="#getting-started" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Getting Started</h2>
<p>
Expand Down Expand Up @@ -107,130 +72,6 @@ <h3><a id="minimal-setup" class="anchor" href="#minimal-setup" aria-hidden="true
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/basic-example-data.component.ts" target="_blank">Demo Source</a>
<code class="typescript">{{ snippets.basicFull }}</code>
</pre>
<h3><a id="separate-filter" class="anchor" href="#separate-filter" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Standalone Filter Example</h3>
<p>
Say you don't need to have a filter field in the each table column or the requirements says that search field should be placed outside of the table?<br>
Fortunately this is super easy to achieve, to do this we need to slightly modify our basic component example.
</p>
<h4><a id="data-source" class="anchor" href="#data-source" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Data Source</h4>
<p>
First thing you need to know is that all the data operations against the table <i>must</i> be done using the <strong>DataSource</strong> table property. DataSource is an abstraction around your data which allows you easily modify the table data or subscribe to events to modify the table behaviour.
</p>
<p>
To access the DataSource we either can take it from the table or pass it instead of our <i>data array</i>. Let's do the second option as it requires less code and is more demonstrative. Let's import the DataSource class by modifying the import statement:
</p>
<pre>
<code class="typescript">{{ snippets.sourceRequire }}</code>
</pre>
<p>
Note that the import now contains a <strong>LocalDataSource</strong> class (the word <i>Local</i> here means that the data is processed locally in a browser, not on the server side).<br>
Then let's create a DataSource instance and pass our data array into it as a constructor parameter:
</p>
<pre>
<code class="typescript">{{ snippets.createSource }}</code>
</pre>
<p>
Now let's pass the source to the table instead of the data array:
</p>
<pre>
<code class="typescript">{{ snippets.sourceTemplate }}</code>
</pre>
<p>
At this point if you look at the result there will be no difference comparing to the first example. Basically if you pass an array to the table component first thing it will do is wrap LocalDataSource object around your array as we did here manually.<br>
Now, having the DataSource we basically could change the table data in any way we need to - filter it, sort, paginate to some page, create/delete/modify the rows. In our example we need to be able to filter the data outside of the table, firstly let's add a search filed to the template with a listener:
</p>
<pre>
<code class="typescript">{{ snippets.search }}</code>
</pre>
<p>
And the listener code which asks the DataSource to filter the data:
</p>
<pre>
<code class="typescript">{{ snippets.searchTable }}</code>
</pre>
<p>
Last thing, let's hide the default table filters to not conflict with our standalone one:
</p>
<pre>
<code class="typescript">{{ snippets.hideFilters }}</code>
</pre>
<p>
And done! Now the table has a standalone search field:
</p>
<div>
<basic-example-source></basic-example-source>
</div>
<p>
Same way you can modify the data of the table, for example by adding a row from a third party form or listening to some external event.
Here's a full component code:
</p>
<pre class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/basic-example-source.component.ts" target="_blank">Demo Source</a>
<code class="typescript">{{ snippets.sourceFull }}</code>
</pre>

<h3><a id="from-server" class="anchor" href="#from-server" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Loading From Server Example</h3>
<p>
This example shows how to pass the data loaded from some API to the table DataSource.
</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/basic-example-load.component.ts" target="_blank">Demo Source</a>
<basic-example-load></basic-example-load>
</div>

<h3><a id="confirm" class="anchor" href="#confirm" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Confirm Action Example</h3>
<p>
An example on how to confirm an action before it's applied to the table:
</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/advanced-example-confirm.component.ts" target="_blank">Demo Source</a>
<advance-example-comfirm></advance-example-comfirm>
</div>
<h3><a id="server" class="anchor" href="#server" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Load From Server Example</h3>
<p>
An example on how to load data user Server DataSource:
</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/advanced-example-server.component.ts" target="_blank">Demo Source</a>
<advanced-example-server></advanced-example-server>
</div>
<h3><a id="types" class="anchor" href="#types" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Select, Completer and Textarea column types</h3>
<p>
An example on how to use select, completer, textarea column types:
</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/advanced-example-types.component.ts" target="_blank">Demo Source</a>
<advanced-example-types></advanced-example-types>
</div>
<h3><a id="custom-editor-renderer" class="anchor" href="#custom-editor-renderer" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Custom editor/renderer column type</h3>
<p>An example on how to use a custom cell editor and/or custom cell renderer:</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/advanced-example-custom-editor.component.ts" target="_blank">Demo Source</a>
<advanced-example-custom-editor></advanced-example-custom-editor>
</div>
<p>When implementing a custom editor or renderer remember to add it to the <code>entryComponents</code> and to the <code>declarations</code> part of your module</p>
<pre>
<code class="typescript">{{ snippets.customEditorModule }}</code>
</pre>
<p>
<b>For the custom cell editor:</b><br>
To inherit the methods needed to interact with the table you can either extend the component with the <code>DefaultEditor</code> class or implement the <code>Editor</code> interface and reproduce the same methods on your component.<br>
<b>For the custom cell renderer:</b><br>
In this example the custom component is applying a <code>.toUpperCase()</code> to one of the columns. You can implement the ViewCell interface to make sure you are setting up your component correctly.
</p>
<h3><a id="multiselect" class="anchor" href="#multiselect" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Multi select</h3>
<p>An example on how to use multi select mode:</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/basic-example-multi-select.component.ts" target="_blank">Demo Source</a>
<basic-example-multi-select></basic-example-multi-select>
</div>
<h3><a id="filters" class="anchor" href="#filters" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Checkbox, Select and Completer filter types</h3>
<p>
An example on how to use the built-in column filter types:
</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/advanced-example-filters.component.ts" target="_blank">Demo Source</a>
<advanced-example-filters></advanced-example-filters>
</div>
<p>Full component documentation you can find <a [routerLink]="['/documentation']">here</a>.</p>
</section>
6 changes: 6 additions & 0 deletions demo/src/app/pages/demo/demo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
}
}

.examples-menu {
a.active {
font-weight: bold;
}
}

@media screen and (max-width: 64em) {
.with-sidebar {

Expand Down
9 changes: 1 addition & 8 deletions demo/src/app/pages/documentation/documentation.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<section class="page-header internal">
<h1 class="project-name"><a [routerLink]="['']">ng2-smart-table</a></h1>
<h2 class="project-tagline">Documentation</h2>

<a routerLinkActive="active" routerLink="/demo" class="btn">Quick Start & Demos</a>
<a routerLinkActive="active" routerLink="/documentation" class="btn">Documentation</a>
<a target="_blank" href="https://github.com/akveo/ng2-smart-table" class="btn">View on GitHub</a>
</section>
<header-component [tagline]="'Documentation'"></header-component>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write a literal value like tagline="Documentation".


<section class="main-content">
<h2><a id="documentation" class="anchor" href="#documentation" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Documentation</h2>
Expand Down
29 changes: 29 additions & 0 deletions demo/src/app/pages/examples/examples-routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename file to examples.routes.ts.

FilterExamplesComponent,
DefaultExampleComponent,
ServerExamplesComponent,
CustomViewEditExamplesComponent,
VariousExamplesComponent } from './examples';

export const examplesRoutes = [
{
path: '',
component: DefaultExampleComponent
},
{
path: 'using-filters',
component: FilterExamplesComponent
},
{
path: 'populate-from-server',
component: ServerExamplesComponent
},
{
path: 'custom-editors-viewers',
component: CustomViewEditExamplesComponent
},
{
path: 'various',
component: VariousExamplesComponent
}
];
8 changes: 8 additions & 0 deletions demo/src/app/pages/examples/examples.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'examples',
templateUrl: 'examples.html'
})
export class ExamplesComponent {
}
13 changes: 13 additions & 0 deletions demo/src/app/pages/examples/examples.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<header-component [tagline]="'Examples'"></header-component>
<section class="main-content with-sidebar">
<nav class="fixed-sidebar">
<h4>Examples</h4>
<ul class="examples-menu">
<li><a routerLink="./using-filters" routerLinkActive="active">Advanced & custom filtering</a></li>
<li><a routerLink="./populate-from-server" routerLinkActive="active">Populating with external data</a></li>
<li><a routerLink="./custom-editors-viewers" routerLinkActive="active">Custom editors and viewers</a></li>
<li><a routerLink="./various" routerLinkActive="active">Various</a></li>
</ul>
</nav>
<router-outlet></router-outlet>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component } from '@angular/core';
import * as hljs from 'highlight.js';

import 'style-loader!../../../../../../node_modules/highlight.js/styles/dracula.css';

import 'style-loader!../../demo/demo.scss';

@Component({
selector: 'custom-edit-view-examples',
templateUrl: './custom-edit-view-examples.html',
})
export class CustomViewEditExamplesComponent {

snippets = {
customEditorModule: require('raw-loader!../snippets/custom-editor-module.md'),
};

ngAfterViewInit(): void {
hljs.initHighlighting();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h2>Customized edit and view cells examples</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, for file naming use angular style guide. For example: custom-edit-view-examples.component.ts, custom-edit-view-examples.component.html, custom-edit-view-examples.component.scss, custom-edit-view-examples.service.ts.

<h3><a id="types" class="anchor" href="#types" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Select, Completer and Textarea column types</h3>
<p>
An example on how to use select, completer, textarea column types:
</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/advanced-example-types.component.ts" target="_blank">Demo Source</a>
<advanced-example-types></advanced-example-types>
</div>
<h3><a id="custom-editor-renderer" class="anchor" href="#custom-editor-renderer" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Custom editor/renderer column type</h3>
<p>An example on how to use a custom cell editor and/or custom cell renderer:</p>
<div class="with-source">
<a class="source" href="https://github.com/akveo/ng2-smart-table/blob/master/demo/src/app/pages/demo/components/advanced-example-custom-editor.component.ts" target="_blank">Demo Source</a>
<advanced-example-custom-editor></advanced-example-custom-editor>
</div>
<p>When implementing a custom editor or renderer remember to add it to the <code>entryComponents</code> and to the <code>declarations</code> part of your module</p>
<pre>
<code class="typescript">{{ snippets.customEditorModule }}</code>
</pre>
<p>
<b>For the custom cell editor:</b><br>
To inherit the methods needed to interact with the table you can either extend the component with the <code>DefaultEditor</code> class or implement the <code>Editor</code> interface and reproduce the same methods on your component.<br>
<b>For the custom cell renderer:</b><br>
In this example the custom component is applying a <code>.toUpperCase()</code> to one of the columns. You can implement the ViewCell interface to make sure you are setting up your component correctly.
</p>
8 changes: 8 additions & 0 deletions demo/src/app/pages/examples/examples/default.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'default-example',
templateUrl: './default.html'
})
export class DefaultExampleComponent {
}
4 changes: 4 additions & 0 deletions demo/src/app/pages/examples/examples/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h2>Advanced examples</h2>
<p>
Use the menu on the right to navigate through the examples.
</p>
27 changes: 27 additions & 0 deletions demo/src/app/pages/examples/examples/filter-examples.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component } from '@angular/core';
import * as hljs from 'highlight.js';

import 'style-loader!../../../../../../node_modules/highlight.js/styles/dracula.css';

import 'style-loader!../../demo/demo.scss';

@Component({
selector: 'filter-examples',
templateUrl: './filter-examples.html',
})
export class FilterExamplesComponent {

snippets = {
sourceRequire: require('raw-loader!../snippets/source-require.md'),
createSource: require('raw-loader!../snippets/create-source.md'),
sourceTemplate: require('raw-loader!../snippets/source-template.md'),
search: require('raw-loader!../snippets/search.md'),
searchTable: require('raw-loader!../snippets/search-table.md'),
sourceFull: require('raw-loader!../snippets/source-full.md'),
hideFilters: require('raw-loader!../snippets/hide-filters.md'),
};

ngAfterViewInit(): void {
hljs.initHighlighting();
}
}
Loading