@ruc-lib/grid-list 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -3
- package/esm2020/lib/ruclib-grid-list/ruclib-grid-list.component.mjs +3 -3
- package/fesm2015/ruc-lib-grid-list.mjs +2 -2
- package/fesm2015/ruc-lib-grid-list.mjs.map +1 -1
- package/fesm2020/ruc-lib-grid-list.mjs +2 -2
- package/fesm2020/ruc-lib-grid-list.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,257 @@
|
|
|
1
1
|
# ruclib-grid-list
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Grid List component is a powerful and versatile tool for displaying data in either a traditional table (list) format or a card-based (grid) format. It comes packed with features like sorting, filtering, pagination, row selection, expandable rows for detailed views, and customizable action columns.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation Guide
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
To use the Grid List component, you can install the entire RUC library or just this specific component.
|
|
8
|
+
|
|
9
|
+
### Install the Entire Library
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @uxpractice/ruc-lib
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Install Individual Component
|
|
16
|
+
|
|
17
|
+
If you only need the Grid List component:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @ruc-lib/grid-list
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Version Compatibility
|
|
25
|
+
|
|
26
|
+
Please ensure you install the correct version of `@ruc-lib/grid-list` based on your Angular version.
|
|
27
|
+
|
|
28
|
+
| Angular Version | Compatible `@ruc-lib/grid-list` Version |
|
|
29
|
+
|--------------------|---------------------------------------------|
|
|
30
|
+
| 15.x.x | `npm install @ruc-lib/grid-list@^3.0.0` |
|
|
31
|
+
| 16.x.x | `npm install @ruc-lib/grid-list@^3.0.0` |
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### 1. Import the Module
|
|
37
|
+
|
|
38
|
+
In your Angular module file (e.g., `app.module.ts`), import the `RuclibGridListModule`:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// For Complete Library
|
|
42
|
+
import { RuclibGridListModule } from '@uxpractice/ruc-lib/grid-list';
|
|
43
|
+
|
|
44
|
+
// For Individual Package
|
|
45
|
+
import { RuclibGridListModule } from '@ruc-lib/grid-list';
|
|
46
|
+
|
|
47
|
+
import { AppComponent } from './app.component';
|
|
48
|
+
import { NgModule } from '@angular/core';
|
|
49
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
50
|
+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
51
|
+
|
|
52
|
+
@NgModule({
|
|
53
|
+
declarations: [AppComponent],
|
|
54
|
+
imports: [BrowserModule, BrowserAnimationsModule, RuclibGridListModule],
|
|
55
|
+
providers: [],
|
|
56
|
+
bootstrap: [AppComponent],
|
|
57
|
+
})
|
|
58
|
+
export class AppModule {}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. Use the Component
|
|
62
|
+
|
|
63
|
+
In your component's template, use the `<uxp-ruclib-grid-list>` selector.
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<uxp-ruclib-grid-list [rucInputData]="gridListConfig" [dataSource]="gridListData" (rucEvent)="handleGridEvent($event)"> </uxp-ruclib-grid-list>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## API Reference
|
|
70
|
+
|
|
71
|
+
### Component Inputs
|
|
72
|
+
|
|
73
|
+
| Input | Type | Description |
|
|
74
|
+
| -------------- | -------- | -------------------------------------------------------------- |
|
|
75
|
+
| `rucInputData` | `object` | The main configuration object for the grid. See details below. |
|
|
76
|
+
| `dataSource` | `any[]` | The array of data to be displayed in the grid. |
|
|
77
|
+
| `customTheme` | `string` | An optional CSS class for custom theming. |
|
|
78
|
+
| `chartConfig` | `any` | Configuration for charts displayed in expandable rows. |
|
|
79
|
+
|
|
80
|
+
### Component Outputs
|
|
81
|
+
|
|
82
|
+
| Output | Type | Description -
|
|
83
|
+
| `rucEvent` | `EventEmitter<any>` | Emits various events from the grid. The event object has an `eventName` and `eventOutput`. Possible `eventName` values are: `sortByColumn`, `paginatorChange`, `currentStateObjChange`. |
|
|
84
|
+
| `rowExpanded` | `EventEmitter<any>` | Emits when a row is expanded or collapsed, providing the row data and an `isExpanded` flag. -
|
|
85
|
+
| `infoClicked` | `EventEmitter<any>` | Emits when an info icon in an action column is clicked, providing the row data. -
|
|
86
|
+
|
|
87
|
+
### `rucInputData`
|
|
88
|
+
|
|
89
|
+
This is the main configuration object for the Grid List component.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface RucInputData {
|
|
93
|
+
gridConfig: GridConfig;
|
|
94
|
+
columnConfig: GridColumnConfig[];
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### `gridConfig`
|
|
99
|
+
|
|
100
|
+
| Property | Type | Description |
|
|
101
|
+
| ------------------- | ---------------------------- | ----------------------------------------------------------------------------------- |
|
|
102
|
+
| `showFilter` | `boolean` | If `true`, a search filter input is displayed. Default is `true`. |
|
|
103
|
+
| `showGridView` | `boolean` | If `true`, icons to toggle between list and grid view are shown. Default is `true`. |
|
|
104
|
+
| `pagination` | `boolean` | If `true`, pagination is enabled. Default is `true`. |
|
|
105
|
+
| `isPaginatedApi` | `boolean` | Set to `true` if pagination is handled by a backend API. Default is `false`. |
|
|
106
|
+
| `isExpandable` | `boolean` | If `true`, rows can be expanded to show more details. Default is `false`. |
|
|
107
|
+
| `isSelectable` | `boolean` | If `true`, a checkbox column for row selection is shown. Default is `true`. |
|
|
108
|
+
| `stickyTableHeader` | `boolean` | If `true`, the table header remains visible while scrolling. Default is `true`. |
|
|
109
|
+
| `cardStyle` | `any` | Custom CSS styles for the cards in grid view. |
|
|
110
|
+
| `showListView` | `boolean` | If `true`, the list view is shown by default. Default is `false`. |
|
|
111
|
+
| `loadData` | `(event?: PageEvent) => any` | A function to load data, typically used with API-driven pagination. |
|
|
112
|
+
| `loadChartData` | `() => any` | A function to load data for charts in expandable rows. |
|
|
113
|
+
|
|
114
|
+
#### `columnConfig`
|
|
115
|
+
|
|
116
|
+
This is an array of objects, where each object configures a column in the grid.
|
|
117
|
+
|
|
118
|
+
| Property | Type | Description |
|
|
119
|
+
| ---------------- | ------------------------------ | --------------------------------------------------------------------------------- |
|
|
120
|
+
| `name` | `string` | A unique identifier for the column. Must match a key in the `dataSource` objects. |
|
|
121
|
+
| `header` | `string` | The text to display in the column header. |
|
|
122
|
+
| `headerStyle` | `any` (optional) | Custom CSS styles for the column header. |
|
|
123
|
+
| `isCustom` | `boolean` (optional) | Set to `true` if you are providing a custom cell template for this column. |
|
|
124
|
+
| `sticky` | `boolean` (optional) | If `true`, the column will be sticky. |
|
|
125
|
+
| `isSort` | `boolean` (optional) | If `true`, enables sorting for this column. |
|
|
126
|
+
| `actionColumn` | `boolean` (optional) | Set to `true` if this column contains action icons. |
|
|
127
|
+
| `action` | `GridListActions[]` (optional) | An array of action configurations for an action column. |
|
|
128
|
+
| `showInCardView` | `boolean` | If `true`, this column's data will be shown on the cards in grid view. |
|
|
129
|
+
|
|
130
|
+
#### `GridListActions`
|
|
131
|
+
|
|
132
|
+
| Property | Type | Description |
|
|
133
|
+
| --------- | ------------------------------------- | ---------------------------------------------- |
|
|
134
|
+
| `icon` | `string` | The name of the Material Icon to display. |
|
|
135
|
+
| `title` | `string` | Tooltip text for the icon. |
|
|
136
|
+
| `handler` | `(event, rowData) => void` (optional) | The function to call when the icon is clicked. |
|
|
137
|
+
|
|
138
|
+
## Custom Column Templates
|
|
139
|
+
|
|
140
|
+
To provide a custom template for a cell, set `isCustom: true` in its `columnConfig`. Then, nest a `<ruc-grid-column>` component inside `<uxp-ruclib-grid-list>` and define the template.
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<uxp-ruclib-grid-list [rucInputData]="gridListConfig" [dataSource]="gridListData">
|
|
144
|
+
<!-- Custom template for the 'name' column -->
|
|
145
|
+
<ruc-grid-column name="name">
|
|
146
|
+
<ng-template #cellTemplate let-element>
|
|
147
|
+
<strong style="color: cornflowerblue;">{{element.name}}</strong>
|
|
148
|
+
</ng-template>
|
|
149
|
+
</ruc-grid-column>
|
|
150
|
+
</uxp-ruclib-grid-list>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Make sure the corresponding `columnConfig` entry is updated:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
{ name: 'name', header: 'Name', showInCardView: true, isCustom: true }
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Example Configuration
|
|
160
|
+
|
|
161
|
+
Here's a comprehensive example of how to configure the Grid List component.
|
|
162
|
+
|
|
163
|
+
**your-component.ts**
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { Component } from '@angular/core';
|
|
167
|
+
import { GridConfig, GridColumnConfig } from '@ruc-lib/grid-list'; // Adjust path if needed
|
|
168
|
+
|
|
169
|
+
@Component({
|
|
170
|
+
selector: 'app-root',
|
|
171
|
+
templateUrl: './app.component.html',
|
|
172
|
+
})
|
|
173
|
+
export class AppComponent {
|
|
174
|
+
gridListData = [
|
|
175
|
+
{ position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H' },
|
|
176
|
+
{ position: 2, name: 'Helium', weight: 4.0026, symbol: 'He' },
|
|
177
|
+
{ position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li' },
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
gridListConfig: {
|
|
181
|
+
gridConfig: GridConfig<any>;
|
|
182
|
+
columnConfig: GridColumnConfig[];
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
constructor() {
|
|
186
|
+
this.gridListConfig = {
|
|
187
|
+
gridConfig: {
|
|
188
|
+
showFilter: true,
|
|
189
|
+
showGridView: true,
|
|
190
|
+
pagination: true,
|
|
191
|
+
isPaginatedApi: false,
|
|
192
|
+
isExpandable: true,
|
|
193
|
+
isSelectable: true,
|
|
194
|
+
stickyTableHeader: true,
|
|
195
|
+
showListView: true,
|
|
196
|
+
},
|
|
197
|
+
columnConfig: [
|
|
198
|
+
{ name: 'position', header: 'No.', showInCardView: true },
|
|
199
|
+
{ name: 'name', header: 'Name', showInCardView: true },
|
|
200
|
+
{ name: 'weight', header: 'Weight', showInCardView: true },
|
|
201
|
+
{ name: 'symbol', header: 'Symbol', showInCardView: false },
|
|
202
|
+
{
|
|
203
|
+
name: 'actions',
|
|
204
|
+
header: 'Actions',
|
|
205
|
+
actionColumn: true,
|
|
206
|
+
showInCardView: false,
|
|
207
|
+
action: [
|
|
208
|
+
{
|
|
209
|
+
icon: 'edit',
|
|
210
|
+
title: 'Edit',
|
|
211
|
+
handler: (event, rowData) => {
|
|
212
|
+
console.log('Edit clicked', rowData);
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
icon: 'delete',
|
|
217
|
+
title: 'Delete',
|
|
218
|
+
handler: (event, rowData) => {
|
|
219
|
+
console.log('Delete clicked', rowData);
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
handleGridEvent(event: any) {
|
|
229
|
+
console.log('Grid Event:', event.eventName, event.eventOutput);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
> ⚠️ **IMPORTANT: Custom Theme Usage in Angular Material**
|
|
235
|
+
|
|
236
|
+
When implementing **custom themes**, such as:
|
|
237
|
+
|
|
238
|
+
```scss
|
|
239
|
+
.custom-theme-1 {
|
|
240
|
+
@include angular-material-theme($custom-theme);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// You must also include the typography mixin to ensure text styles are applied correctly as shown below:
|
|
244
|
+
.custom-theme-1 {
|
|
245
|
+
@include angular-material-theme($custom-theme);
|
|
246
|
+
@include mat.typography-level($theme-custom-typography-name, body-1);
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
## Contribution
|
|
252
|
+
|
|
253
|
+
Contributions are welcome! Feel free to open issues or pull requests for any enhancements or fixes.
|
|
254
|
+
|
|
255
|
+
## Acknowledgements
|
|
256
|
+
|
|
257
|
+
Thank you for choosing the Grid List component. If you have any feedback or suggestions, please let us know!
|