Gathering detailed insights and metrics for @acpaas-ui-widgets/ngx-smart-table
Gathering detailed insights and metrics for @acpaas-ui-widgets/ngx-smart-table
Gathering detailed insights and metrics for @acpaas-ui-widgets/ngx-smart-table
Gathering detailed insights and metrics for @acpaas-ui-widgets/ngx-smart-table
npm install @acpaas-ui-widgets/ngx-smart-table
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This is the Angular 6+ UI for a Smart Widget implementing a table whose configuration is provided by the backend. When the corresponding API is implemented in the BFF, it provides automatic support for column types, filtering, pagination and sorting without additional client-side coding.
Check the latest changes in the changelog.
A showcase app for the smart table component:
1> npm install 2> npm start
Browse to localhost:4200
1> npm install @acpaas-ui-widgets/ngx-smart-table
Prerequisite: set up Antwerp UI for your application.
Import the component in your module:
1import { SmartTableModule } from '@acpaas-ui-widgets/ngx-smart-table'; 2 3@NgModule({ 4 imports: [ 5 ..., 6 SmartTableModule 7 ], 8 ... 9})
1<aui-smart-table 2 apiUrl="/api/your-table-bff" 3 (rowClicked)="onRowClicked($event)"> 4</aui-smart-table>
1SmartTableModule.withLabels
2 .forRoot({
3 identifier: 'aui-smarttable-ngx',
4 storageType: 'sessionStorage',
5 labels: {
6 itemCounterLabel: {
7 singular: '%{currentFrom} - %{currentTo} van %{totalAmount} film',
8 plural: '%{currentFrom} - %{currentTo} van %{totalAmount} films',
9 },
10 itemsPerPageLabel: {
11 singular: 'film per pagina',
12 plural: 'films per pagina',
13 },
14 columnOrdering: { // Optional
15 orderBefore: 'Verplaats kolom naar voor',
16 orderAfter: 'Verplaats kolomn naar achter'
17 }
18 },
19 options: {
20 useLowerCaseQueryParams: true, // Some APIs require all lower case query params
21 noConfigApiCall: false, // Skip the /config call and provide all config in the frontend
22 noExport: false // If true hides the export button
23 exportWithFilters: false // If true filters and sorting will be respected in export. pagination will still be removed.
24 }
25 })
The apiUrl
points to the corresponding back-end service (see below).
In the component code:
1class YourComponent { 2 3 onRowClicked(row) { 4 // do something... 5 } 6}
Every value in the backing list must have a unique id.
/config
to get default setup configuration. Setting this option to true will enable the component to
parse frontend-only configuration by setting the configuration attribute on the component, without making backend config calls.
Check the example application for how these are used.
The smart table loads its configuration and data from a back-end service provided by the apiUrl
input.
Look at projects/example-api/api.js
for the example API.
This back-end service must implement the following protocol:
/path/to/endpoint?page=1&pageSize=20
page
starts from 1, pageSize
is the number of rows per page./path/to/endpoint/all
/path/to/endpoint/config
SmartTableConfig
in projects/smart-table/src/lib/smart-table/smart-table.types.ts.The POST
endpoints accept the following JSON body:
1{ 2 "filters": [{ 3 "fields": string[], /* field id's */ 4 "operator": string, /* '=' or 'ILIKE' */ 5 "value": string|{ id: string } 6 }, ...], 7 "sort": { 8 "path": string /* field id */, 9 "ascending": boolean 10 } 11}
And they return the following response:
1{ 2 "_embedded": { 3 "resourceList": [{ 4 "field_id": "value" 5 }] 6 }, 7 "_page": { 8 "size": number /* nr of rows per page */, 9 "totalElements": number /* nr of rows across all pages */, 10 "totalPages": number /* nr of pages */, 11 "number": number /* current page, starts from 1 */, 12 } 13}
By default the column visibility is automatically saved in localStorage
under the aui-smart-table
prefix.
This may cause conflicts with other apps running on the same URL, especially on localhost.
To configure column visibility to use a different storage prefix for your app, include the module in this way:
1SmartTableModule.forRoot({
2 identifier: 'your-unique-identifier', // default = aui-smart-table
3 storageType: 'localStorage' // localStorage (default) / sessionStorage / memory
4})
Use an identifier unique for your application.
On each table the persistence is adjusted with the configuration fields:
options.persistTableConfig
(boolean): whether the column settings are persisted locallyoptions.storageIdentifier
(string): the identifier to store settings in for this table (should be unique per table)The column settings will be persisted to the storage configured in SmartTableModule using the settings provided in the table options.
The smart table determines its functionality from the provided configuration.
This is provided in two ways:
GET .../config
, a call to the server to fetch the configurationcustomConfiguration
, a local override for the values obtained from the serverThe complete configuration object can be found in src/lib/smart-table/smart-table.types.ts
as SmartTableConfig
.
An explanation of the properties of the configuration object:
columns
: array, the columns configuration of the table
type
: string, text
/number
/date
/dateTime
key
: string, field key in the row data object, also used for state persistencelabel
: string, text to show in column headervisible
: boolean, column should be visible by defaultclassList
: string[], list of custom css classes to apply to the column cellssortPath
: string, key to sort on (passed to server in data query)canHide
: boolean, whether the column can be hidden by the user
(tip: to include columns that are always hidden, put them only in the data object, not in the columns config)filters
: array, the possible filters configuration of the table
id
: string, unique id for the filtertype
: string, how to present the filter: select
, input
(text), datepicker
display
: string, how to show the filter in the UI
generic
: a google-like search textbox to search across multiple fields, always shownvisible
: field-specific filter control, always shownoptional
: field-specific filter control, hidden behind 'Extra filters' buttonlabel
: string, label to show next to filter controlfield
: string, key of the field (column) to filter onfields
: string[], keys of the fields to filter on, for filter type generic
operator
: string, operator to compare the value with, =
/ ILIKE
options
: {id: string, label: string}[], content of dropdown list for filter type select
placeholder
: stringvalue
: string | {id: string, label: string}[]baseFilters
: array, a set of fixed and hidden filters to always apply to data requests
fields
: string[], keys of the fields to filter onoperator
: string, operator to compare the value with, =
/ ILIKE
value
: string | {id: string, label: string}[]options
: object, other configuration for the table
defaultSortOrder
: { key: string, order: 'asc'|'desc' }, initial sort orderloadDataMessage
: string, shown while loadingnoDataMessage
: string, shown when emptyerrorMessage
: string, shown when loading failedpageSize
: number, initial page size (in rows)pageSizeOptions
: number[], choices presented for page size in the UIresetSortOrderOnFilter
: boolean, return to default sort order when changing filterscolumnDateTimeFormat
: string, default format for date/time columns, see https://angular.io/api/common/DatePipecolumnDateFormat
: string, default format for date columns, see https://angular.io/api/common/DatePipestorageIdentifier
: string, unique key for persisting column statepersistTableConfig
: boolean, true to persist column statetranslations
: object, translation strings to replace default (Dutch) text in UI (see smart-table.types.ts
)The default column types are text, number, date and dateTime. Sometimes a special column type is needed.
In the showcase example there is a custom column for the star rating.
To implement a custom column:
Cell
from ngx-table. Use rating.component.ts
as an example.1<aui-smart-table 2 [columnTypes]="myCustomColumns"
1myCustomColumns = [{ 2 name: 'mycustom', 3 component: MyCustomColumnComponent 4}];
1columns: [{ 2 key: 'myfield', 3 label: 'Custom column', 4 type: 'mycustom' 5}]
We welcome your bug reports and pull requests.
Please see our contribution guide.
Joeri Sebrechts (joeri.sebrechts@digipolis.be)
This project is published under the MIT license.
No vulnerabilities found.
No security vulnerabilities found.