Skip to content
This repository was archived by the owner on Dec 25, 2021. It is now read-only.

Commit 27a0887

Browse files
Bruzzano, BrunoBruzzano, Bruno
authored andcommitted
Deep refactor.
1 parent be1b9ed commit 27a0887

115 files changed

Lines changed: 15780 additions & 6461 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.angular-cli.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"project": {
4+
"name": "angular5-datatable"
5+
},
6+
"apps": [
7+
{
8+
"root": "src",
9+
"name": "app",
10+
"outDir": "dist/app",
11+
"assets": [
12+
"assets",
13+
"favicon.ico",
14+
{"glob": "**/*","input":"./app/components/datatable/","output":"./assets/src/datatable"},
15+
{"glob": "**/*.md","input":"../libs/datatable/src/","output":"./assets/src/datatable"}
16+
],
17+
"index": "index.html",
18+
"main": "main.ts",
19+
"polyfills": "polyfills.ts",
20+
"test": "test.ts",
21+
"tsconfig": "tsconfig.app.json",
22+
"testTsconfig": "tsconfig.spec.json",
23+
"prefix": "app",
24+
"styles": [
25+
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
26+
"../node_modules/font-awesome/css/font-awesome.css",
27+
"styles.css"
28+
],
29+
"scripts": [],
30+
"environmentSource": "environments/environment.ts",
31+
"environments": {
32+
"dev": "environments/environment.ts",
33+
"prod": "environments/environment.prod.ts"
34+
}
35+
},
36+
{
37+
"root": "src",
38+
"name": "packages",
39+
"outDir": "dist/app",
40+
"assets": [
41+
"assets",
42+
"favicon.ico"
43+
],
44+
"index": "index.html",
45+
"main": "main.ts",
46+
"polyfills": "polyfills.ts",
47+
"test": "test.ts",
48+
"tsconfig": "tsconfig.packages.json",
49+
"testTsconfig": "tsconfig.spec.json",
50+
"prefix": "app",
51+
"styles": [
52+
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
53+
"../node_modules/font-awesome/css/font-awesome.css",
54+
"styles.css"
55+
],
56+
"scripts": [],
57+
"environmentSource": "environments/environment.ts",
58+
"environments": {
59+
"dev": "environments/environment.ts",
60+
"prod": "environments/environment.prod.ts"
61+
}
62+
}
63+
],
64+
"e2e": {
65+
"protractor": {
66+
"config": "./protractor.conf.js"
67+
}
68+
},
69+
"lint": [
70+
{
71+
"project": "src/tsconfig.app.json",
72+
"exclude": "**/node_modules/**"
73+
},
74+
{
75+
"project": "src/tsconfig.packages.json",
76+
"exclude": "**/node_modules/**"
77+
},
78+
{
79+
"project": "src/tsconfig.spec.json",
80+
"exclude": "**/node_modules/**"
81+
},
82+
{
83+
"project": "e2e/tsconfig.e2e.json",
84+
"exclude": "**/node_modules/**"
85+
}
86+
],
87+
"test": {
88+
"karma": {
89+
"config": "./karma.conf.js"
90+
}
91+
},
92+
"defaults": {
93+
"styleExt": "css",
94+
"component": {}
95+
}
96+
}

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.travis.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Bruno Bruzzano
3+
Copyright (c) 2018 Bruno Bruzzano
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

Lines changed: 145 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Angular 5 Data Table
1+
# Angular 5 DataTable
22

3-
Note: Originally, it was fork of this [package](https://github.com/MIt9/angular-4-data-table).
3+
*Note*: Originally this was fork of this [package](https://github.com/MIt9/angular-4-data-table).
44

55
A simple Angular 5 data table, with built-in solutions for features including:
66
* pagination
@@ -9,19 +9,153 @@ A simple Angular 5 data table, with built-in solutions for features including:
99
* expandable rows
1010
* column resizing
1111
* selecting visible columns
12-
* accessibility (basic)
12+
* accessibility
1313

14-
It's based on Bootstrap v4.0.0 and Font v4.7.0, so you need to include them in the application using it.
14+
The component can be used not just with local data, but remote resources too, ie. when sorting and/or pagination are implemented server side.
1515

16-
The component can be used not just with local data, but remote resources too: for example if the sorting and paging happen in the database.
16+
The library is packaged with [`ng-packgr`](https://github.com/dherges/ng-packagr).
1717

18-
Checkout [this](https://ggmod.github.io/angular-2-data-table-demo/) for a demo.
18+
## Dependencies
19+
Furthermore the component is based on Bootstrap v4.0 (*CSS-only*) and Font-Awesome v4.7, hence be sure to include them into your project.
20+
Most likely you need to install them as dependencies...
1921

20-
## Installing
21-
`npm install angular5-data-table --save`
22+
```bash
23+
npm install bootstrap@4.0.0 font-awesome@4.7.0
24+
```
25+
26+
... then you need to include the CSS bundles into .angular-cli.json file as show below.
27+
```json
28+
{
29+
"apps": [
30+
{
31+
"root": "src",
32+
"styles": [
33+
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
34+
"../node_modules/font-awesome/css/font-awesome.css",
35+
"styles.css"
36+
]
37+
}
38+
]
39+
}
40+
```
41+
42+
## Installation
43+
44+
```bash
45+
npm install @angular5/datatable
46+
```
47+
48+
## Usage
49+
50+
##### 1.Import Datatable module
51+
```ts
52+
import { BrowserModule } from '@angular/platform-browser';
53+
import { NgModule } from '@angular/core';
54+
import { DataTableModule } from '@angular5/datatable';
55+
56+
@NgModule({
57+
imports: [
58+
...
59+
DataTableModule.forRoot()
60+
...
61+
],
62+
bootstrap: [AppComponent]
63+
})
64+
export class AppModule { }
65+
```
66+
67+
##### 2. Include `<data-table>` and `<data-table-column>` into your component's template.
68+
```HTML
69+
<!-- my.component.template -->
70+
<div>
71+
...
72+
<data-table id="my-table"
73+
...
74+
[title]="'Employees'"
75+
[items]="items"
76+
[itemCount]="itemCount"
77+
...
78+
>
79+
<data-table-column
80+
[property]="'name'"
81+
[header]="'name'"
82+
... >
83+
</data-table-column>
84+
<data-table-column
85+
...
86+
</data-table-column>
87+
</data-table>
88+
...
89+
</div>
90+
```
91+
92+
## API
93+
94+
### data-table
95+
* `title` (`string` | default: `''`) table's name - it's highly recommend it's set for accessibility reasons as this will provide a better experience when interacting with the component, especially through a SR.
96+
* `showTitle` (`boolean` | default: `true`): if `false`, the title is not shown into the component. Useful when want the header component visible (with its Reload and Coulumn Selector buttons), but not the title.
97+
* `items` (`JsonObject[]` | default: `[]`) table data to show.
98+
* `itemsCount` (`number` | default: `0`) items's count.
99+
* `header` (`boolean` | default: `true`) show/hide the table header sub-component - this holds the table name and two buttons (_reload table_ and _column selector_).
100+
* `pagination` (`boolean` | default: ) enable pagination. If `true`, pagination controls are shown at the bottom of the table.
101+
* `indexColumn` (`boolean` | default: `true`) when `true` the table shows a 0-indexed column.
102+
* `indexColumnHeader` (`string` | default: `''`) text shown as column header for the index column.
103+
* `selectColumn` (`boolean` | default: `false`) when `true` the table shows a checkbox column for selecting specific row.
104+
* `multiSelect` (`boolean` | default: `false`) allows multi-row selection, showing a checkbox at select's column header.
105+
* `labels` (`DataTableTranslations` | default: `defaultTranslations`) interface holding all needed labels. You can pass a subset of the labels. The missing labels will be defaulted.
106+
* `expandableRow` (`boolean` | default: `false`) when `true` each row will have a collapsible content.
107+
* `selectOnRowClick` (`boolean` | default: `false`) when `true` each row is selectable via a single-click.
108+
* `reload` (`function(): void` | default: `null`) function that is invoked when the table needs to re-render its data. Note: most of the times this is the place where the developer connects to a server in order to pull down the item set.
109+
* `autoReload` (`boolean` | default: `false`) when `true`, the `reload` function gets invoked and init time (`ngOnInit`).
110+
* `rowColors` (`function(): 'color` | default: `null`) custom function that must return a _CSS color_ that will be applied to the entire row.
111+
* `rowTooltip` (`function` | default: `null`) custom function to show a title tooltip when hovering the row.
112+
* `showReloading` (`boolean` | default: `true`) when `true` an overlay with a gear icon is shown on top of the table while it's reloading.
113+
* `noDataMessage` (`string` | default: `''`) message displayed when no item are displayed. If it's empty nothing is shown.
114+
* `pageLimits` (`number[]` | default: `[10, 25, 50, 100, 250]`) items per page selector options.
115+
* `primaryColumn` (`string` | default: first data column) it identifies which columns has be marked as primary. This is an important aspect from an accessibility and SR perspective. If not given, the first column will be the primary column.
116+
* `page` (`number` | default: `0`) page to load, valid only if pagination is enabled.
117+
* `limit` (`number` | default: `10`) number of items per page, valid only pagination is enabled. If `limit` value is not a valid (not contained into `pageLimits` array) it will be defaulted to `pageLimits`'s first value.
118+
* `sortBy` (`string` | default: `''`) column table is sorted by.
119+
* `sortAsc` (`boolean` | default: `true`) valid only if `sortBy` is not defaulted. Defines the sorting order. If `true` sort is ascending, descending otherwise.
120+
121+
### data-table-column
122+
* `property` (`string` | default: _no default_) item's `JSONObject` key used to retrieve the row cell content.
123+
* `header` (`string` | default: _no default_) column header text.
124+
* `sortable` (`boolean` | default: `false`) marks the columns as sortable.
125+
* `resizable` (`boolean` | default: `false`) marks the columns as resizable.
126+
* `visible` (`boolean` | default: `true`) marks the columns visible.
127+
* `width` (`number | string` | default: `''`) defines the column width. It can be a string like `2rem` or a number. If it's a number, it will be considered as pixels.
128+
129+
### Custom column templates
130+
data-column's content and header are not restricted to be text only - they can hold complex content too. In order to do that developers can use two references: `#dataTableHeader` and `#dataTableCell`.
131+
132+
# Usage and sample
133+
```html
134+
</data-table>
135+
...
136+
<data-table-column
137+
header="Actions">
138+
<ng-template #dataTableHeader let-item="item">
139+
<i>Actions</i>
140+
</ng-template>
141+
<ng-template #dataTableCell let-item="item">
142+
<button (click)="carClicked(item)" class="btn btn-sm btn-default">Buy</button>
143+
</ng-template>
144+
</data-table-column>
145+
...
146+
</data-table>
147+
```
148+
As it can be seen from the above snippet, the `dataTableHeader` and `dataTableCell` are targeting two `<ng-template>`s nodes which will be used respectively as column header and cell content. In both cases `item` refers to the whole row item, so developers can use whatever they may need.
149+
150+
## Demo app
151+
Clone this repository, run `npm install` and `ng serve`, then navigate to `http:localhost:4200` where you can access to the demo application sporting a few demos with code viewer and docs.
152+
153+
##Examples
154+
![Demo1](https://user-images.githubusercontent.com/4410485/39678176-ce90ecc6-517f-11e8-82fd-ec85162ccf80.png)
155+
![Demo2](https://user-images.githubusercontent.com/4410485/39678189-fcd6a080-517f-11e8-8cca-6dd5395703b0.png)
156+
![Demo3](https://user-images.githubusercontent.com/4410485/39678197-1513fed6-5180-11e8-8ad6-64c08c9689fa.png)
157+
![Demo4](https://user-images.githubusercontent.com/4410485/39678201-29df8740-5180-11e8-80f5-68249311aa20.png)
158+
![Demo5](https://user-images.githubusercontent.com/4410485/39678204-425001f6-5180-11e8-8b7d-1decacd406a6.png)
22159

23-
## Development
24-
For creating a distributable version, run `npm run build`, then run `npm run pack-lib`. This will create a tar.gz file containing the library, which can be installed within your projects. The packager system is based on [Angular Library Starter](https://github.com/robisim74/angular-library-starter/)
25-
26160
## License
27161
MIT License

banner.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)