ngx-lite-form 1.4.1 → 1.4.2

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 CHANGED
@@ -62,7 +62,7 @@ Lite Form provides 15+ form and UI components. Click on any component below for
62
62
  - **[LiteFile](docs/lite-file.md)** - File upload with drag & drop and camera capture
63
63
 
64
64
  ### Data Display & Navigation
65
- - **[LiteTable](docs/lite-table.md)** - Flexible data table with pagination and row actions
65
+ - **[LiteTable](docs/lite-table.md)** - Flexible data table with sorting, pagination, and row actions
66
66
  - **[LitePaginator](docs/lite-paginator.md)** - Standalone pagination component
67
67
 
68
68
  ### UI Components
@@ -198,12 +198,12 @@ export class AppComponent {
198
198
  showPreview: true
199
199
  });
200
200
 
201
- // Table with custom columns
201
+ // Table with custom columns and sorting
202
202
  employeeTable = new TableFieldDto(
203
203
  [
204
- { key: 'name', label: 'Name', flex: '1' },
205
- { key: 'department', label: 'Department', flex: '0 0 150px' },
206
- { key: 'salary', label: 'Salary', flex: '0 0 120px', cellTemplate: (value) => `$${value?.toLocaleString() || '0'}` }
204
+ { key: 'name', label: 'Name', flex: '1', sortable: true },
205
+ { key: 'department', label: 'Department', flex: '0 0 150px', sortable: true },
206
+ { key: 'salary', label: 'Salary', flex: '0 0 120px', sortable: true, cellTemplate: (value) => `$${value?.toLocaleString() || '0'}` }
207
207
  ],
208
208
  [
209
209
  { name: 'John Smith', department: 'Engineering', salary: 75000 },
@@ -211,17 +211,25 @@ export class AppComponent {
211
211
  ]
212
212
  );
213
213
 
214
- // Paginated table
214
+ // Paginated table with sorting
215
215
  userTable = new TableFieldDto(
216
216
  [
217
- { key: 'name', label: 'Name', flex: '1' },
218
- { key: 'email', label: 'Email', flex: '1' },
219
- { key: 'location.country', label: 'Country', flex: '0 0 120px' }
217
+ { key: 'name', label: 'Name', flex: '1', sortable: true },
218
+ { key: 'email', label: 'Email', flex: '1', sortable: true },
219
+ { key: 'location.country', label: 'Country', flex: '0 0 120px', sortable: true }
220
220
  ],
221
221
  [], // Will be populated by API
222
222
  true, // Enable pagination
223
223
  new PaginatorFieldDto(1, 100, 10) // Page 1, 100 total items, 10 per page
224
224
  );
225
+
226
+ // Handle sort changes
227
+ onTableSort(event: { column: string; direction: 'asc' | 'desc' | null }) {
228
+ this.userTable = {
229
+ ...this.userTable,
230
+ sortState: { column: event.column, direction: event.direction }
231
+ };
232
+ }
225
233
 
226
234
  // Standalone paginator
227
235
  paginator = new PaginatorFieldDto(1, 500, 25);
@@ -262,16 +270,22 @@ export class AppComponent {
262
270
  <lite-file [control]="fileField"></lite-file>
263
271
  </form>
264
272
 
265
- <!-- Data Table -->
266
- <lite-table [table]="employeeTable"></lite-table>
273
+ <!-- Data Table with Sorting -->
274
+ <lite-table
275
+ [table]="employeeTable"
276
+ (sortChange)="onTableSort($event)">
277
+ </lite-table>
267
278
 
268
- <!-- Paginated Table -->
279
+ <!-- Paginated Table with Sorting -->
269
280
  <lite-table
270
281
  [table]="userTable"
271
282
  (pageChange)="onPageChange($event)"
272
- (itemsPerPageChange)="onItemsPerPageChange($event)">
283
+ (itemsPerPageChange)="onItemsPerPageChange($event)"
284
+ (sortChange)="onTableSort($event)">
273
285
  </lite-table>
274
286
 
287
+ > Sorting behavior: LiteTable performs client-side, page-level sorting. Only the currently visible page is sorted. Disable pagination to sort the full visible dataset, or sort on the server before passing data to the table if you need whole-dataset sorting across pages.
288
+
275
289
  <!-- Standalone Paginator -->
276
290
  <lite-paginator
277
291
  [paginator]="paginator"
@@ -420,18 +434,26 @@ class FileFieldDto {
420
434
  Table configuration for the LiteTable component.
421
435
 
422
436
  ```typescript
437
+ type SortDirection = 'asc' | 'desc' | null;
438
+
439
+ interface SortState {
440
+ column: string;
441
+ direction: SortDirection;
442
+ }
443
+
423
444
  class TableFieldDto<T = any> {
424
445
  columns: TableColumn[];
425
446
  data: T[];
426
447
  showPaginator?: boolean;
427
448
  paginatorConfig: PaginatorFieldDto;
449
+ sortState?: SortState; // Current sort state
428
450
  }
429
451
 
430
452
  interface TableColumn {
431
453
  key: string; // Data property key (supports dot notation)
432
454
  label: string; // Column header text
433
455
  flex?: string; // CSS flex property (e.g., '0 0 100px', '1')
434
- sortable?: boolean; // Show sorting indicator
456
+ sortable?: boolean; // Enable sorting for this column
435
457
  cellTemplate?: (value: any, row: any) => string; // Custom HTML template
436
458
  type?: 'text' | 'menu'; // Optional column type (default: 'text')
437
459
  menuItems?: Array<{ label: string; value: string; variant?: 'danger' | 'default' }>; // For 'menu' type columns
@@ -511,4 +533,4 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu
511
533
 
512
534
  ---
513
535
  ## Changelog
514
- - See [docs/CHANGELOG.md](https://github.com/liangk/lite-form/blob/main/docs/CHANGELOG.md) for the full historical record, including the latest `v1.4.1` release with LiteDateTime selection state fix.
536
+ - See [docs/CHANGELOG.md](https://github.com/liangk/lite-form/blob/main/docs/CHANGELOG.md) for the full historical record, including the latest `v1.4.2` release with LiteTable column sorting feature.