Repository navigation
Expand file tree
/
Copy pathtable-demo.component.ts
More file actions
1366 lines (1290 loc) · 65.4 KB
/
Copy pathtable-demo.component.ts
File metadata and controls
1366 lines (1290 loc) · 65.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { DecimalPipe } from '@angular/common';
import { DemoPageComponent, DemoSectionComponent } from '../../../shared/demo-page.component';
import { SdButton } from '@sdcorejs/angular/components/button';
import { SdModal } from '@sdcorejs/angular/components/modal';
import { SdSideDrawer } from '@sdcorejs/angular/components/side-drawer';
import { SdCheckbox } from '@sdcorejs/angular/forms/checkbox';
import { TableAggregateDemoComponent } from './table-aggregate-example.component';
import {
SdTable,
SdTableOption,
SdTableCellDefDirective,
SdTableRowMobileDefDirective,
SdTableCommandHeaderDefDirective,
SdTableExpandDefDirective,
SdTableGroupDefDirective,
SdMaterialFooterDefDirective,
SdTableItem,
SdTableQuickSearchRightDefDirective,
} from '@sdcorejs/angular/components/table';
interface QuickSearchCustomer {
code: string;
name: string;
phone: string;
email: string;
tenantId: string;
}
const QUICK_SEARCH_CUSTOMERS: QuickSearchCustomer[] = [
{ code: 'KH-001', name: 'Nguyễn Minh An', phone: '0900000001', email: 'an@example.com', tenantId: 'north' },
{ code: 'KH-002', name: 'Trần Thanh Bình', phone: '0900000002', email: 'binh@example.com', tenantId: 'north' },
{ code: 'KH-003', name: 'Lê Hoàng An', phone: '0900000003', email: 'hoang@example.com', tenantId: 'south' },
{ code: 'KH-004', name: 'Phạm Thu Dung', phone: '0900000004', email: 'an.dung@example.com', tenantId: 'south' },
];
interface Employee {
id: number;
name: string;
department: string;
position: string;
salary: number;
status: 'ACTIVE' | 'PROBATION' | 'RESIGNED';
joinDate: Date;
active: boolean;
email: string;
}
interface Product {
id: number;
code: string;
name: string;
amount: number;
stock: number;
active: boolean;
}
interface OrgNode {
id: number;
name: string;
role: string;
headcount: number;
children?: OrgNode[];
}
interface Task {
id: number;
title: string;
assignee: string;
priority: 'high' | 'medium' | 'low';
progress: number;
description: string;
}
interface Order {
id: number;
code: string;
customerId: number;
customerName: string;
customerPhone: string;
product: string;
qty: number;
amount: number;
date: Date;
}
const EMPLOYEES: Employee[] = [
{ id: 1, name: 'Nguyễn Văn An', department: 'TECH', position: 'Trưởng phòng', salary: 35_000_000, status: 'ACTIVE', joinDate: new Date(2020, 0, 15), active: true, email: 'an.nv@company.vn' },
{ id: 2, name: 'Trần Thị Bình', department: 'SALES', position: 'Nhân viên', salary: 18_000_000, status: 'ACTIVE', joinDate: new Date(2021, 4, 1), active: true, email: 'binh.tt@company.vn' },
{ id: 3, name: 'Lê Hoàng Cường', department: 'TECH', position: 'Senior Dev', salary: 28_000_000, status: 'PROBATION', joinDate: new Date(2024, 11, 1), active: true, email: 'cuong.lh@company.vn' },
{ id: 4, name: 'Phạm Thị Dung', department: 'HR', position: 'Chuyên viên', salary: 16_000_000, status: 'ACTIVE', joinDate: new Date(2022, 2, 10), active: true, email: 'dung.pt@company.vn' },
{ id: 5, name: 'Hoàng Minh Em', department: 'FINANCE', position: 'Kế toán', salary: 17_500_000, status: 'RESIGNED', joinDate: new Date(2019, 7, 20), active: false, email: 'em.hm@company.vn' },
{ id: 6, name: 'Vũ Văn Phúc', department: 'MARKETING', position: 'Trưởng nhóm', salary: 22_000_000, status: 'ACTIVE', joinDate: new Date(2021, 9, 5), active: true, email: 'phuc.vv@company.vn' },
{ id: 7, name: 'Đỗ Thu Giang', department: 'SALES', position: 'Trưởng phòng', salary: 32_000_000, status: 'ACTIVE', joinDate: new Date(2018, 1, 12), active: true, email: 'giang.dt@company.vn' },
{ id: 8, name: 'Bùi Quang Huy', department: 'TECH', position: 'Junior Dev', salary: 14_000_000, status: 'PROBATION', joinDate: new Date(2025, 0, 4), active: true, email: 'huy.bq@company.vn' },
];
const PRODUCTS: Product[] = [
{ id: 1, code: 'SP-001', name: 'Laptop Dell Latitude 5430', amount: 22_500_000, stock: 12, active: true },
{ id: 2, code: 'SP-002', name: 'Màn hình LG UltraWide 34"', amount: 9_800_000, stock: 8, active: true },
{ id: 3, code: 'SP-003', name: 'Bàn phím cơ Keychron K6', amount: 2_300_000, stock: 0, active: false },
{ id: 4, code: 'SP-004', name: 'Chuột Logitech MX Master 3S', amount: 2_750_000, stock: 25, active: true },
{ id: 5, code: 'SP-005', name: 'Tai nghe Sony WH-1000XM5', amount: 7_500_000, stock: 4, active: true },
];
const ORG: OrgNode[] = [
{
id: 1, name: 'Khối Công nghệ', role: 'Division', headcount: 42, children: [
{ id: 11, name: 'Phòng Backend', role: 'Department', headcount: 18, children: [
{ id: 111, name: 'Nhóm API', role: 'Team', headcount: 8 },
{ id: 112, name: 'Nhóm Data', role: 'Team', headcount: 10 },
] },
{ id: 12, name: 'Phòng Frontend', role: 'Department', headcount: 14 },
{ id: 13, name: 'Phòng QA', role: 'Department', headcount: 10 },
],
},
{
id: 2, name: 'Khối Kinh doanh', role: 'Division', headcount: 28, children: [
{ id: 21, name: 'Phòng Sales Bắc', role: 'Department', headcount: 16 },
{ id: 22, name: 'Phòng Sales Nam', role: 'Department', headcount: 12 },
],
},
];
// Lazy tree demo: chỉ có root sẵn, children nạp theo yêu cầu (giả lập API trễ).
const LAZY_ROOTS: OrgNode[] = [
{ id: 1, name: 'Khối Công nghệ', role: 'Division', headcount: 42 },
{ id: 2, name: 'Khối Kinh doanh', role: 'Division', headcount: 28 },
];
const LAZY_CHILDREN: Record<number, OrgNode[]> = {
1: [
{ id: 11, name: 'Phòng Backend', role: 'Department', headcount: 18 },
{ id: 12, name: 'Phòng Frontend', role: 'Department', headcount: 14 },
],
11: [
{ id: 111, name: 'Nhóm API', role: 'Team', headcount: 8 },
{ id: 112, name: 'Nhóm Data', role: 'Team', headcount: 10 },
],
2: [
{ id: 21, name: 'Phòng Sales Bắc', role: 'Department', headcount: 16 },
{ id: 22, name: 'Phòng Sales Nam', role: 'Department', headcount: 12 },
],
};
const ORDERS: Order[] = [
{ id: 1, code: 'ORD-001', customerId: 1, customerName: 'Nguyễn Văn An', customerPhone: '0912345678', product: 'Laptop Dell', qty: 1, amount: 22_500_000, date: new Date(2026, 4, 1) },
{ id: 2, code: 'ORD-002', customerId: 1, customerName: 'Nguyễn Văn An', customerPhone: '0912345678', product: 'Chuột Logitech', qty: 2, amount: 5_500_000, date: new Date(2026, 4, 3) },
{ id: 3, code: 'ORD-003', customerId: 1, customerName: 'Nguyễn Văn An', customerPhone: '0912345678', product: 'Tai nghe Sony', qty: 1, amount: 7_500_000, date: new Date(2026, 4, 10) },
{ id: 4, code: 'ORD-004', customerId: 2, customerName: 'Trần Thị Bình', customerPhone: '0987654321', product: 'Màn hình LG', qty: 1, amount: 9_800_000, date: new Date(2026, 4, 2) },
{ id: 5, code: 'ORD-005', customerId: 2, customerName: 'Trần Thị Bình', customerPhone: '0987654321', product: 'Bàn phím Keychron', qty: 1, amount: 2_300_000, date: new Date(2026, 4, 8) },
{ id: 6, code: 'ORD-006', customerId: 3, customerName: 'Lê Hoàng Cường', customerPhone: '0901234567', product: 'Laptop Macbook', qty: 1, amount: 45_000_000, date: new Date(2026, 4, 5) },
{ id: 7, code: 'ORD-007', customerId: 3, customerName: 'Lê Hoàng Cường', customerPhone: '0901234567', product: 'Magic Mouse', qty: 1, amount: 2_500_000, date: new Date(2026, 4, 6) },
{ id: 8, code: 'ORD-008', customerId: 4, customerName: 'Phạm Thị Dung', customerPhone: '0934567890', product: 'iPad Pro', qty: 1, amount: 28_000_000, date: new Date(2026, 4, 12) },
];
const TASKS: Task[] = [
{ id: 1, title: 'Tích hợp cổng thanh toán VNPay', assignee: 'An', priority: 'high', progress: 65, description: 'Triển khai SDK VNPay phase 1 — sandbox + production switch, log audit, retry policy 3 lần.' },
{ id: 2, title: 'Sửa lỗi NaN cột STT', assignee: 'Bình', priority: 'medium', progress: 100, description: 'Cột STT hiển thị NaN khi multiTemplateDataRows=true. Đã đổi sang renderIndex.' },
{ id: 3, title: 'Migrate import sdcorejs/utils', assignee: 'Cường', priority: 'low', progress: 80, description: 'Chuyển 80 file production code dùng @sdcorejs/angular/utilities sang @sdcorejs/utils. 4 batch parallel.' },
];
@Component({
selector: 'app-table-demo',
standalone: true,
imports: [
DemoPageComponent,
DemoSectionComponent,
DecimalPipe,
SdTable,
SdTableCellDefDirective,
SdTableRowMobileDefDirective,
SdTableCommandHeaderDefDirective,
SdTableExpandDefDirective,
SdTableGroupDefDirective,
SdMaterialFooterDefDirective,
SdButton,
SdModal,
SdSideDrawer,
SdCheckbox,
SdTableQuickSearchRightDefDirective,
TableAggregateDemoComponent,
],
template: `
<demo-page #demoPage
title="Table"
description="Bảng dữ liệu mặc định của SDCoreJS — phân trang, sắp xếp, lọc, chọn nhiều, lệnh dòng, export Excel/CSV. Hỗ trợ chế độ local và server.">
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-quick-search') {
<demo-section heading="Quick search"
[props]="[{ name: 'filter.quickSearch', value: 'containFields / equalFields / filters' }, { name: 'default', value: 'Signal' }, { name: 'sdTableQuickSearchRightDef', value: 'template' }]"
note="Chọn tenant áp dụng ngay; nhập từ khóa rồi nhấn Enter. Tên/email tìm chứa, mã/SĐT tìm chính xác; email không cần có cột. Đổi tenant ở màn A rồi chuyển màn B để thấy lựa chọn được giữ bằng signal chung. Checkbox bên phải là UI do consumer chèn vào.">
<div class="d-flex gap-8 mb-16">
<sd-button title="Màn A" size="sm" [type]="quickScreen() === 'A' ? 'fill' : 'outline'" (click)="quickScreen.set('A')" />
<sd-button title="Màn B" size="sm" [type]="quickScreen() === 'B' ? 'fill' : 'outline'" (click)="quickScreen.set('B')" />
</div>
@for (screen of quickScreens; track screen) {
@if (quickScreen() === screen) {
<sd-table [autoId]="'quick-search-' + screen" [option]="quickSearchOptions[screen]">
<ng-template sdTableQuickSearchRightDef>
<sd-checkbox label="Ẩn bộ chọn tenant" size="sm" [model]="hideQuickTenant()" (sdChange)="hideQuickTenant.set(!!$event)" />
</ng-template>
</sd-table>
}
}
<p class="T12R text-secondary mt-12" role="status">{{ quickSearchLog() }}</p>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-external-filters') {
<demo-section heading="External filters"
[props]="[{ name: 'filter.externalFilters', value: 'string / values / number / daterange' }, { name: 'filter.manualFilter', value: 'true' }]"
note="Bộ lọc gọn, có khoảng đệm với mép section. Nhập điều kiện rồi nhấn Tìm kiếm; nút xóa và thiết lập nằm trên header. Bảng bo nhẹ ở các góc ngoài, vẫn cuộn và giữ header cố định.">
<sd-table autoId="external-filters" [option]="externalFilterOption" />
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-the-mobile-va-thao-tac') {
<demo-section heading="Thẻ mobile và thao tác"
[props]="[{ name: 'sdTableRowMobileDef', value: 'template' }, { name: 'mobile.rowLabel', value: 'callback' }, { name: 'selector.actions', value: '[…]' }, { name: 'command.commands', value: '[…]' }]"
note="Nút Thêm canh giữa phía trên card. Lề card hai bên cố định, checkbox nhỏ nằm đè góc phải border. Thanh chọn chừa 16px hai đầu; nhiều action tự xuống hàng đều. Chạm card mở sheet thao tác dòng; nút Công cụ ở footer mở sheet tải lại, xuất, lọc và sắp xếp.">
<sd-table autoId="mobile-employees" [option]="mobileOption">
<ng-template sdTableCommandHeaderDef>
<sd-button title="Thêm" prefixIcon="add" type="text" (click)="recordMobile('Thêm dòng', [])"></sd-button>
</ng-template>
<ng-template [sdTableRowMobileDef]="mobileOption" let-row="item" let-selected="selected" let-disabled="selectionDisabled">
<div class="T12M text-secondary">NV-{{ row.id }} · {{ row.department }}</div>
<strong class="T16M d-block mt-4">{{ row.name }}</strong>
<div class="T14R mt-4">{{ row.position }}</div>
<div class="T14M mt-8">{{ row.salary | number }} ₫</div>
@if (disabled && !selected) { <p class="T12R text-secondary">Chỉ xem — chưa đủ điều kiện chọn</p> }
<a [href]="'#employee-' + row.id" (click)="recordMobile('Liên kết hồ sơ', [row.id]); $event.preventDefault()">Hồ sơ</a>
<sd-button title="Ghi chú" type="text" prefixIcon="edit_note" (click)="recordMobile('Ghi chú trong card', [row.id])"></sd-button>
</ng-template>
<ng-template sdTableExpandDef let-item="item"><div class="p-12">{{ item.data.email }} · {{ item.data.status }}</div></ng-template>
<ng-template sdTableFooterDef="salary" let-items="items"><strong>{{ totalSalary(items) | number }} ₫ / trang</strong></ng-template>
</sd-table>
<p class="T14R mt-12" role="status">{{ mobileLog() }}</p>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-mobile-qua-nhieu-trang') {
<demo-section heading="Mobile qua nhiều trang"
[props]="[{ name: 'type', value: 'server' }, { name: 'rowKey', value: 'id' }, { name: 'preserveSelection', value: 'true' }, { name: 'sdTableRowMobileDef', value: 'template' }]"
note="API giả lập trả object mới sau mỗi request. Chọn ở trang 1 rồi sang trang 2; summary và callback giữ toàn bộ selection.">
<sd-table autoId="mobile-server" [option]="mobileServerOption">
<ng-template [sdTableRowMobileDef]="mobileServerOption" let-row="item">
<strong class="T16M">NV-{{ row.id }} · {{ row.name }}</strong>
<div class="T14R mt-8">{{ row.department }} · {{ row.salary | number }} ₫</div>
</ng-template>
</sd-table>
<p role="status">{{ mobileLog() }}</p>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-mobile-chon-du-lieu') {
<demo-section heading="Mobile chọn dữ liệu"
[props]="[{ name: 'selector.single', value: 'true' }, { name: 'selector.actions', value: '[]' }, { name: 'selector.visible', value: 'false' }, { name: 'defaultSelected', value: 'callback' }]"
note="Ba table độc lập: chọn đơn có mặc định; chọn nhiều không có bulk action; chỉ có lệnh dòng.">
<sd-table autoId="mobile-single" [option]="mobileSingleOption">
<ng-template [sdTableRowMobileDef]="mobileSingleOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.department }}</div></ng-template>
</sd-table>
<sd-table class="mt-16" autoId="mobile-no-actions" [option]="mobileNoActionsOption">
<ng-template [sdTableRowMobileDef]="mobileNoActionsOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.position }}</div></ng-template>
</sd-table>
<sd-table class="mt-16" autoId="mobile-commands-only" [option]="mobileCommandsOnlyOption">
<ng-template [sdTableRowMobileDef]="mobileCommandsOnlyOption" let-row="item"><strong>{{ row.name }}</strong><div>Chỉ thao tác theo dòng</div></ng-template>
</sd-table>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-mobile-trong-hop-thoai') {
<demo-section heading="Mobile trong hộp thoại"
[props]="[{ name: 'sdTableRowMobileDef', value: 'template' }, { name: 'sd-modal', value: 'container' }, { name: 'sd-side-drawer', value: 'container' }]"
note="Card và thanh thao tác nằm trong vùng cuộn của từng table. Đóng hộp thoại hoặc drawer sẽ dọn các overlay con.">
<div class="d-flex gap-8 flex-wrap">
<sd-button title="Mở modal" (click)="mobileModal.open()"></sd-button>
<sd-button title="Mở drawer" (click)="mobileDrawer.open()"></sd-button>
</div>
<sd-modal #mobileModal title="Nhân viên trong modal" width="md">
<sd-table class="p-12" autoId="mobile-modal" [option]="mobileOption">
<ng-template [sdTableRowMobileDef]="mobileOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.position }}</div></ng-template>
</sd-table>
</sd-modal>
<sd-side-drawer #mobileDrawer title="Nhân viên trong drawer" width="480px">
<sd-table class="p-12" autoId="mobile-drawer" [option]="mobileOption">
<ng-template [sdTableRowMobileDef]="mobileOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.position }}</div></ng-template>
</sd-table>
</sd-side-drawer>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-full-demo-local') {
<demo-section heading="Full demo (local)" [props]="[{ name: 'selector', value: 'true' }, { name: 'command', value: 'true' }, { name: 'export', value: 'true' }, { name: 'index', value: 'true' }, { name: 'filler', value: 'true' }, { name: 'paginate', value: 'true' }]">
<div class="table-box">
<sd-table [option]="employeeOption"></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-toi-gian') {
<demo-section heading="Tối giản" [props]="[{ name: 'paginate', value: 'true' }]">
<div class="table-box">
<sd-table [option]="productOption"></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-filter-onchange') {
<demo-section
heading="Filter onChange"
[props]="[
{ name: 'columns[].filter.onChange', value: 'callback' },
{ name: 'input / input-number', value: 'Enter / blur' }
]"
note="Callback chỉ chạy khi giá trị filter đã commit và khác lần trước; input text/number commit bằng Enter hoặc blur.">
<div class="table-box">
<div class="filter-change-log">
<span class="filter-change-log__label">Callback cuối:</span>
<span>{{ filterOnChangeEvent() }}</span>
</div>
<sd-table [option]="filterOnChangeOption"></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-chon-mot-dong') {
<demo-section heading="Chọn một dòng" [props]="[{ name: 'selector.single', value: 'true' }]">
<div class="table-box">
<sd-table [option]="singleSelectOption"><ng-template [sdTableRowMobileDef]="singleSelectOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.position }}</div></ng-template></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-tree-rows-search-o-cap-con-go-ten-don-vi-con-de-loc') {
<demo-section
heading="Tree rows + search ở cấp con (gõ tên đơn vị con để lọc)"
[props]="[
{ name: 'tree.loadType', value: 'static' },
{ name: 'tree.childrenKey', value: 'children' },
{ name: 'tree.defaultExpanded', value: '1' },
{ name: 'columns[].filter', value: 'config' }
]"
note="Search trên table 'local' + tree 'static' lọc cả cấp con: giữ nhánh cha của node khớp, prune sibling không khớp, tự bung tới node khớp.">
<div class="table-box">
<sd-table [option]="treeOption"><ng-template [sdTableRowMobileDef]="treeOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.role }}</div></ng-template></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-tree-lazy-nap-con-khi-bung-co-loading') {
<demo-section
heading="Tree lazy — nạp con khi bung (có loading)"
[props]="[
{ name: 'tree.loadType', value: 'lazy' },
{ name: 'tree.onExpandChildren', value: 'Promise' },
{ name: 'tree.hasChildren', value: 'method' }
]"
note="loadType 'lazy': bung dòng → gọi onExpandChildren (giả lập trễ 800ms) → spinner loading hiện trong ô chevron tới khi nạp xong. hasChildren quyết định dòng nào có icon expand (Nhóm/Team là lá → không icon).">
<div class="table-box">
<sd-table [option]="treeLazyOption"><ng-template [sdTableRowMobileDef]="treeLazyOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.role }}</div></ng-template></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-tree-khong-cot-stt-chevron-nam-trong-cot-dau-don-vi') {
<demo-section
heading="Tree KHÔNG cột STT — chevron nằm trong cột đầu (Đơn vị)"
[props]="[
{ name: 'tree.loadType', value: 'static' },
{ name: 'index', value: 'false' }
]"
note="Không bật index → icon expand + indent nhúng thẳng vào cột data đầu tiên (kiểu file explorer).">
<div class="table-box">
<sd-table [option]="treeNoIndexOption"><ng-template [sdTableRowMobileDef]="treeNoIndexOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.role }}</div></ng-template></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-tree-selector-command-chinh-indent') {
<demo-section
heading="Tree + selector + command + chỉnh indent"
[props]="[
{ name: 'tree.indentSize', value: treeCommandIndentSize() + 'px' },
{ name: 'selector.visible', value: 'true' },
{ name: 'command.align', value: 'right' }
]"
note="Demo phối hợp tree rows với checkbox selector, bulk actions, command theo từng dòng và thay đổi indent trực tiếp.">
<div class="table-box">
<div class="tree-command-toolbar">
<span class="tree-command-toolbar__label">Indent: {{ treeCommandIndentSize() }}px</span>
<sd-button
type="light"
color="secondary"
prefixIcon="format_indent_decrease"
title="Giảm indent"
[disabled]="treeCommandIndentSize() <= 8"
(click)="decreaseTreeCommandIndent()">
</sd-button>
<sd-button
type="light"
color="primary"
prefixIcon="format_indent_increase"
title="Tăng indent"
[disabled]="treeCommandIndentSize() >= 32"
(click)="increaseTreeCommandIndent()">
</sd-button>
</div>
<sd-table [option]="treeCommandOption()"><ng-template [sdTableRowMobileDef]="treeCommandOption()" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.role }}</div></ng-template></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-nhom-dong') {
<demo-section heading="Nhóm dòng" [props]="[{ name: 'group', value: 'true' }, { name: 'sdTableGroupDef', value: 'template' }]">
<div class="table-box">
<sd-table [option]="groupOption">
<ng-template [sdTableRowMobileDef]="groupOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.department }}</div></ng-template>
<ng-template sdTableGroupDef let-values="values" let-data="data" let-isExpanded="isExpanded">
<div class="group-header-cell">
<span class="group-label">Phòng <b>{{ values['department'] }}</b></span>
<span class="group-meta">— {{ data.length }} nhân viên · trạng thái: {{ isExpanded ? 'expand' : 'collapse' }}</span>
</div>
</ng-template>
</sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-nhom-don-hang-theo-khach') {
<demo-section heading="Nhóm đơn hàng theo khách" [props]="[{ name: 'group', value: 'true' }, { name: 'sdTableGroupDef', value: 'template' }]">
<div class="table-box">
<sd-table [option]="customerOrderOption">
<ng-template [sdTableRowMobileDef]="customerOrderOption" let-row="item"><strong>{{ row.code }}</strong><div>{{ row.product }}</div><div>{{ row.amount | number }} ₫</div></ng-template>
<ng-template sdTableGroupDef let-values="values" let-data="data">
<div class="group-header-cell">
<span class="group-label">
Khách: <b>{{ values['customerId'] === 1 ? 'Nguyễn Văn An' : values['customerId'] === 2 ? 'Trần Thị Bình' : values['customerId'] === 3 ? 'Lê Hoàng Cường' : 'Phạm Thị Dung' }}</b>
</span>
<span class="group-meta">
— {{ data.length }} đơn · Tổng: {{ totalOrderAmount(data) | number: '1.0-0' }} ₫
</span>
</div>
</ng-template>
</sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-dong-mo-rong') {
<demo-section heading="Dòng mở rộng" [props]="[{ name: 'expand', value: 'true' }, { name: 'sdTableExpandDef', value: 'template' }]">
<div class="table-box">
<sd-table [option]="expandOption">
<ng-template [sdTableRowMobileDef]="expandOption" let-row="item"><strong>{{ row.title }}</strong><div>{{ row.assignee }} · {{ row.progress }}%</div></ng-template>
<ng-template sdTableExpandDef let-item="item">
<div class="expand-box">
<div class="expand-title">Mô tả task #{{ item.data.id }}</div>
<p>{{ item.data.description }}</p>
<div class="expand-meta">
Người phụ trách: <b>{{ item.data.assignee }}</b> · Tiến độ: <b>{{ item.data.progress }}%</b>
</div>
</div>
</ng-template>
</sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-lenh-dong-phai') {
<demo-section heading="Lệnh dòng phải"
[props]="[{ name: 'command.align', value: 'right' }, { name: 'command.commands[].disabled', value: '(row) => boolean' }]"
note="SP-003 minh họa lệnh Sửa và Xóa bị vô hiệu hóa: icon nhạt màu, lệnh Xem vẫn sử dụng được.">
<div class="table-box">
<sd-table [option]="commandRightOption"></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-lenh-dong-co-menu-con') {
<demo-section
heading="Lệnh dòng có menu con"
[props]="[
{ name: 'command.commands[].children', value: 'SdTableCommandNormal[]' },
{ name: 'command.align', value: 'right' }
]"
note="Command và action children dùng menu gọn nền trắng. Chọn dòng để thử action nhóm; các child command vẫn hỗ trợ icon, title, color, disabled, hidden và click theo từng row.">
<div class="table-box">
<sd-table autoId="command-children-demo" [option]="commandChildrenOption"><ng-template [sdTableRowMobileDef]="commandChildrenOption" let-row="item"><strong>{{ row.code }}</strong><div>{{ row.name }}</div></ng-template></sd-table>
<p role="status">{{ commandChildrenEvent() }}</p>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-action-da-chon-co-menu-con') {
<demo-section
heading="Action đã chọn có menu con"
[props]="[
{ name: 'selector.actions[].children', value: 'menu' },
{ name: 'selector.defaultSelected', value: 'callback' }
]"
note="Một dòng được chọn sẵn. Mở Xử lý đã chọn ở thanh dưới bảng để thử menu con; chọn thêm dòng để kiểm tra danh sách truyền vào callback.">
<div class="table-box">
<sd-table autoId="action-children-demo" [option]="actionChildrenOption"></sd-table>
<p role="status">{{ actionChildrenEvent() }}</p>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-keo-tha-doi-thu-tu') {
<demo-section heading="Kéo thả đổi thứ tự" [props]="[{ name: 'rowReorder', value: 'true' }]">
<div class="table-box">
<sd-table [option]="reorderOption"><ng-template [sdTableRowMobileDef]="reorderOption" let-row="item"><strong>{{ row.code }}</strong><div>{{ row.name }}</div></ng-template></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-hanh-dong-o-header-cot-command') {
<demo-section
heading="Hành động ở header cột command"
[props]="[{ name: 'sdTableCommandHeaderDef', value: 'template' }]"
note="Ô header của cột command vốn để trống. Chiếu nội dung vào đó để đặt một hành động cấp bảng (ở đây là thêm dòng) ngay trên cụm sửa/xoá của từng dòng, khỏi cần thêm một dải riêng dưới bảng.">
<div class="table-box">
<sd-table [option]="commandHeaderOption">
<ng-template [sdTableRowMobileDef]="commandHeaderOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.department }}</div></ng-template>
<ng-template sdTableCommandHeaderDef>
<sd-button prefixIcon="add" type="text" color="primary" tooltip="Thêm dòng" (click)="addCommandHeaderRow()"></sd-button>
</ng-template>
</sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-cell-template-tuy-chinh') {
<demo-section heading="Cell template tùy chỉnh" [props]="[{ name: 'sdTableCellDef', value: 'template' }]">
<div class="table-box">
<sd-table [option]="customCellOption">
<ng-template [sdTableCellDef]="'name'" let-item="item">
<div class="name-cell">
<span class="avatar">{{ item.name.charAt(0) }}</span>
<div>
<div class="name-line">{{ item.name }}</div>
<div class="email-line">{{ item.email }}</div>
</div>
</div>
</ng-template>
<ng-template [sdTableCellDef]="'status'" let-item="item">
<span class="chip chip-{{ item.status.toLowerCase() }}">{{ item.status }}</span>
</ng-template>
</sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-column-aggregate') {
<demo-section heading="Column aggregate" [props]="[{ name: 'column.aggregate', value: 'built-in / callback / template' }]"
data-example-typescript="./table-aggregate-example.component.ts" data-example-template="./table-aggregate-example.component.html"
note="Tổng độc lập phía trên footer: local page/filtered, COUNT, grouped headers, row groups, tree và lazy children. Server filtered không được hỗ trợ; chỉ tính page hoặc tự cung cấp nghiệp vụ tổng bên ngoài table.">
<app-table-aggregate-demo />
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-footer-tong-hop') {
<demo-section heading="Footer tổng hợp" [props]="[{ name: 'sdTableFooterDef', value: 'template' }]">
<div class="table-box">
<sd-table [option]="footerOption">
<ng-template [sdTableRowMobileDef]="footerOption" let-row="item"><strong>{{ row.name }}</strong><div>{{ row.salary | number }} ₫</div></ng-template>
<ng-template [sdTableFooterDef]="'salary'" let-items="items">
<b>Tổng: {{ totalSalary(items) | number: '1.0-0' }} ₫</b>
</ng-template>
<ng-template [sdTableFooterDef]="'name'" let-items="items">
<span>{{ items.length }} nhân viên</span>
</ng-template>
</sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-khong-co-filler') {
<demo-section heading="Không có filler" [props]="[{ name: 'filler', value: 'false' }]">
<div class="table-box">
<sd-table [option]="noFillerOption"></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-server-side') {
<demo-section heading="Server-side" [props]="[{ name: 'type', value: 'server' }]">
<div class="table-box">
<sd-table [option]="serverOption"></sd-table>
</div>
</demo-section>
}
@if (!demoPage.focusedSectionId || demoPage.focusedSectionId === 'example-giu-selection-xuyen-trang') {
<demo-section heading="Giữ selection xuyên trang" [props]="[{ name: 'selector.preserveSelection', value: 'true' }]">
<div class="table-box">
<sd-table [option]="preserveSelectionOption"></sd-table>
</div>
</demo-section>
}
</demo-page>
`,
styles: [`
.table-box { width: 100%; }
.tree-command-toolbar {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
margin-bottom: 10px;
}
.tree-command-toolbar__label {
color: #4b5563;
font-size: 13px;
font-weight: 600;
}
.expand-box {
padding: 12px 16px;
background: #fafafa;
border-left: 3px solid var(--sd-primary, #005cbb);
}
.expand-title {
font-weight: 600;
margin-bottom: 6px;
}
.expand-meta {
margin-top: 8px;
font-size: 12px;
color: #555;
}
.name-cell {
display: flex;
align-items: center;
gap: 8px;
}
.avatar {
width: 28px;
height: 28px;
border-radius: 50%;
background: var(--sd-primary, #005cbb);
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
font-weight: 600;
font-size: 12px;
}
.name-line { font-weight: 600; }
.email-line { font-size: 12px; color: #777; }
.chip {
display: inline-block;
padding: 2px 10px;
border-radius: 12px;
font-size: 12px;
font-weight: 600;
}
.chip-active { background: #e6f7ec; color: #1f7a3e; }
.chip-probation { background: #fff4e0; color: #b3691a; }
.chip-resigned { background: #fde7e7; color: #b32626; }
.group-header-cell {
display: inline-flex;
align-items: baseline;
gap: 8px;
font-size: 14px;
}
.group-label { font-weight: 600; }
.group-meta { color: #777; font-size: 12px; }
.filter-change-log {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: #374151;
font-size: 13px;
}
.filter-change-log__label {
color: #6b7280;
font-weight: 600;
}
`],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TableDemoComponent {
readonly quickScreens = ['A', 'B'] as const;
readonly quickScreen = signal<'A' | 'B'>('A');
readonly quickTenant = signal<string | null>('north');
readonly hideQuickTenant = signal(false);
readonly quickSearchLog = signal('Tenant dùng chung: Miền Bắc. Dữ liệu minh họa.');
readonly quickSearchOptions = { A: this.createQuickSearchOption('A'), B: this.createQuickSearchOption('B') };
private createQuickSearchOption(screen: 'A' | 'B'): SdTableOption<QuickSearchCustomer> {
return {
type: 'local', rowKey: 'code', items: () => QUICK_SEARCH_CUSTOMERS,
filter: { key: `demo-quick-search-${screen}`, cacheable: true, quickSearch: {
containFields: ['name', 'email'], equalFields: ['code', 'phone'],
placeholder: 'Tên, email, mã KH hoặc số điện thoại…',
filters: [{
field: 'tenantId', title: 'Tenant', type: 'values', required: true,
default: this.quickTenant, hidden: this.hideQuickTenant,
option: { valueField: 'id', displayField: 'name', items: [{ id: 'north', name: 'Miền Bắc' }, { id: 'south', name: 'Miền Nam' }] },
onChange: value => {
this.quickTenant.set(typeof value === 'string' ? value : null);
this.quickSearchLog.set(`Màn ${screen} đã chọn tenant: ${value || '(chưa chọn)'}. Màn còn lại sẽ dùng lựa chọn này.`);
},
}],
} },
columns: [
{ field: 'code', title: 'Mã KH', type: 'string', width: '120px' },
{ field: 'name', title: 'Khách hàng', type: 'string', width: '240px' },
{ field: 'phone', title: 'Số điện thoại', type: 'string', width: '180px' },
],
reload: { visible: true }, export: { visible: 'ALL', fileName: 'quick-search-customers' },
};
}
readonly externalFilterOption: SdTableOption<Employee> = {
type: 'server',
items: async ({ rawExternalFilter, pageNumber, pageSize }) => {
// Mock API: consumer xử lý external filters từ request của table.
const { name, department, salary, joinDate } = rawExternalFilter;
const term = String(name ?? '').trim().toLocaleLowerCase();
const from = joinDate?.from ? new Date(joinDate.from).setHours(0, 0, 0, 0) : undefined;
const to = joinDate?.to ? new Date(joinDate.to).setHours(23, 59, 59, 999) : undefined;
const rows = EMPLOYEES.filter(row =>
(!term || row.name.toLocaleLowerCase().includes(term)) &&
(!department || row.department === department) &&
(salary === undefined || salary === null || salary === '' || row.salary === Number(salary)) &&
(from === undefined || row.joinDate.getTime() >= from) &&
(to === undefined || row.joinDate.getTime() <= to)
);
return { items: rows.slice(pageNumber * pageSize, (pageNumber + 1) * pageSize), total: rows.length };
},
filter: {
hideInlineFilter: true, manualFilter: true, externalFilterPerRow: 4,
externalFilters: [
{ field: 'name', title: 'Họ và tên', type: 'string', defaultShowing: true },
{ field: 'department', title: 'Phòng ban', type: 'values', defaultShowing: true,
option: { valueField: 'value', displayField: 'display', items: [
{ value: 'TECH', display: 'Công nghệ' }, { value: 'SALES', display: 'Kinh doanh' },
{ value: 'HR', display: 'Nhân sự' }, { value: 'FINANCE', display: 'Tài chính' },
{ value: 'MARKETING', display: 'Marketing' },
] } },
{ field: 'salary', title: 'Lương', type: 'number', defaultShowing: true },
{ field: 'joinDate', title: 'Ngày vào làm', type: 'daterange', defaultShowing: true },
],
},
columns: [
{ field: 'name', title: 'Họ và tên', type: 'string', width: '220px', fixed: true },
{ field: 'department', title: 'Phòng ban', type: 'string', width: '180px' },
{ field: 'position', title: 'Chức vụ', type: 'string', width: '220px' },
{ field: 'salary', title: 'Lương', type: 'number', width: '180px' },
{ field: 'joinDate', title: 'Ngày vào làm', type: 'date', width: '180px' },
],
reload: { visible: true }, style: { maxHeight: '240px' },
};
readonly filterOnChangeEvent = signal('Chưa có thay đổi');
readonly employeeOption: SdTableOption<Employee> = {
type: 'local',
key: 'showcase-employee-table',
items: () => EMPLOYEES,
sort: { enable: true },
paginate: { pageSize: 5, pages: [5, 10, 25] },
config: { visible: true, resizable: true },
index: { enabled: true },
filler: { enabled: true },
selector: {
visible: true,
actions: [
{ icon: 'mail', title: 'Gửi email', click: items => alert(`Gửi email tới ${items?.length} nhân viên`) },
{ icon: 'delete', title: 'Xóa', color: 'error', click: items => alert(`Xóa ${items?.length} nhân viên`) },
],
message: items => `Đã chọn ${items?.length ?? 0} nhân viên`,
},
command: {
align: 'right',
commands: [
{ icon: 'edit', title: 'Sửa', click: (e: Employee) => alert(`Sửa: ${e.name}`) },
{ icon: 'delete', title: 'Xóa', color: 'error', click: (e: Employee) => alert(`Xóa: ${e.name}`) },
],
},
export: { visible: 'EXCEL' },
columns: [
{ field: 'name', type: 'string', title: 'Họ và tên', width: '180px', sortable: true },
{ field: 'email', type: 'string', title: 'Email', width: '220px' },
{
field: 'department', type: 'values', title: 'Phòng ban', width: '140px',
option: {
items: [
{ value: 'TECH', display: 'Công nghệ' },
{ value: 'SALES', display: 'Kinh doanh' },
{ value: 'HR', display: 'Nhân sự' },
{ value: 'FINANCE', display: 'Tài chính' },
{ value: 'MARKETING', display: 'Marketing' },
],
valueField: 'value',
displayField: 'display',
},
},
{ field: 'position', type: 'string', title: 'Chức vụ', width: '160px' },
{ field: 'salary', type: 'number', title: 'Lương', width: '140px', align: 'right', sortable: true },
{
field: 'status', type: 'values', title: 'Trạng thái', width: '130px',
option: {
items: [
{ value: 'ACTIVE', display: 'Đang làm việc' },
{ value: 'PROBATION', display: 'Thử việc' },
{ value: 'RESIGNED', display: 'Đã nghỉ' },
],
valueField: 'value',
displayField: 'display',
},
useBadge: (v: string) => v === 'ACTIVE'
? { title: 'Đang làm việc', color: 'success' }
: v === 'PROBATION'
? { title: 'Thử việc', color: 'warning' }
: { title: 'Đã nghỉ', color: 'error' },
},
{ field: 'joinDate', type: 'date', title: 'Ngày vào', width: '130px' },
],
style: { shadow: true, maxHeight: '460px' },
};
readonly productOption: SdTableOption<Product> = {
type: 'local',
items: () => PRODUCTS,
sort: { enable: true },
paginate: { pageSize: 5, hidePageSize: true },
filler: { enabled: true },
columns: [
{ field: 'code', type: 'string', title: 'Mã SP', width: '120px' },
{ field: 'name', type: 'string', title: 'Tên sản phẩm', width: '320px' },
{ field: 'amount', type: 'number', title: 'Giá bán (VND)', width: '160px', align: 'right' },
{
field: 'stock', type: 'number', title: 'Tồn kho', width: '120px', align: 'right',
useBadge: (v: number) => v === 0
? { title: 'Hết hàng', color: 'error' }
: v < 5
? { title: `${v} (sắp hết)`, color: 'warning' }
: { title: `${v}`, color: 'success' },
},
{ field: 'active', type: 'boolean', title: 'Kích hoạt', width: '120px', option: { displayOnTrue: 'Có', displayOnFalse: 'Không' } },
],
style: { shadow: true },
};
readonly filterOnChangeOption: SdTableOption<Product> = {
type: 'local',
key: 'showcase-filter-on-change-table',
items: () => PRODUCTS,
sort: { enable: true },
paginate: { pageSize: 5, hidePageSize: true },
filler: { enabled: true },
columns: [
{ field: 'code', type: 'string', title: 'Mã SP', width: '120px' },
{
field: 'name',
type: 'string',
title: 'Tên sản phẩm',
width: '320px',
filter: {
default: '',
onChange: value => this.recordFilterOnChange('Tên sản phẩm', value),
},
},
{
field: 'stock',
type: 'number',
title: 'Tồn kho',
width: '120px',
align: 'right',
filter: {
onChange: value => this.recordFilterOnChange('Tồn kho', value),
},
},
{
field: 'active',
type: 'boolean',
title: 'Kích hoạt',
width: '120px',
option: { displayOnTrue: 'Có', displayOnFalse: 'Không' },
},
],
style: { shadow: true },
};
readonly singleSelectOption: SdTableOption<Employee> = {
type: 'local',
items: () => EMPLOYEES.slice(0, 5),
selector: { visible: true, single: true, message: items => `Đã chọn: ${items?.[0]?.name ?? '(chưa chọn)'}` },
index: { enabled: true },
filler: { enabled: true },
columns: [
{ field: 'name', type: 'string', title: 'Họ tên', width: '200px' },
{ field: 'department', type: 'string', title: 'Phòng ban', width: '140px' },
{ field: 'position', type: 'string', title: 'Chức vụ', width: '180px' },
],
style: { shadow: true },
};
readonly treeOption: SdTableOption<OrgNode> = {
type: 'local',
items: () => ORG,
tree: { loadType: 'static', childrenKey: 'children', defaultExpanded: 1, indentSize: 16 },
index: { enabled: true },
filler: { enabled: true },
// why: bật inline filter để demo search ở cấp con — gõ tên đơn vị con,
// table giữ nhánh cha + tự bung tới node khớp (static + type 'local').
columns: [
{ field: 'name', type: 'string', title: 'Đơn vị', width: '280px', filter: { default: '' } },
{ field: 'role', type: 'string', title: 'Cấp', width: '140px' },
{ field: 'headcount', type: 'number', title: 'Số nhân sự', width: '140px', align: 'right' },
],
style: { shadow: true },
};
readonly treeLazyOption: SdTableOption<OrgNode> = {
type: 'local',
items: () => LAZY_ROOTS,
tree: {
loadType: 'lazy',
indentSize: 16,
// hasChildren: chỉ dòng thực sự có con mới hiện icon expand.
hasChildren: row => !!LAZY_CHILDREN[row.id]?.length,
// onExpandChildren: giả lập API trễ 800ms để thấy spinner loading khi bung.
onExpandChildren: row =>
new Promise<OrgNode[]>(resolve => setTimeout(() => resolve(LAZY_CHILDREN[row.id] ?? []), 800)),
},
index: { enabled: true },
filler: { enabled: true },
columns: [
{ field: 'name', type: 'string', title: 'Đơn vị', width: '280px' },
{ field: 'role', type: 'string', title: 'Cấp', width: '140px' },
{ field: 'headcount', type: 'number', title: 'Số nhân sự', width: '140px', align: 'right' },
],
style: { shadow: true },
};
// Tree không bật index → chevron + indent nhúng vào cột data đầu (Đơn vị).
readonly treeNoIndexOption: SdTableOption<OrgNode> = {
type: 'local',
items: () => ORG,
tree: { loadType: 'static', childrenKey: 'children', defaultExpanded: 1, indentSize: 16 },
filler: { enabled: true },
columns: [
{ field: 'name', type: 'string', title: 'Đơn vị', width: '320px' },
{ field: 'role', type: 'string', title: 'Cấp', width: '160px' },
{ field: 'headcount', type: 'number', title: 'Số nhân sự', width: '160px', align: 'right' },
],
style: { shadow: true },
};
readonly treeCommandIndentSize = signal(16);
readonly treeCommandOption = computed<SdTableOption<OrgNode>>(() => ({
type: 'local',
key: 'showcase-tree-selector-command-table',
items: () => ORG,
tree: { loadType: 'static', childrenKey: 'children', defaultExpanded: true, indentSize: this.treeCommandIndentSize() },
selector: {
visible: true,
actions: [
{ icon: 'download', title: 'Xuất đơn vị', click: items => alert(`Xuất ${items?.length ?? 0} đơn vị`) },
{ icon: 'account_tree', title: 'Gộp báo cáo', click: items => alert(`Gộp báo cáo cho ${items?.length ?? 0} đơn vị`) },
],
message: items => `Đã chọn ${items?.length ?? 0} đơn vị`,
},
command: {
align: 'right',
commands: [
{
icon: row => row.children?.length ? 'account_tree' : 'person',
title: row => `Xem ${this.describeOrgNode(row)}`,
click: row => alert(`Xem ${this.describeOrgNode(row)}`),
},
{
icon: 'add',
title: 'Thêm đơn vị con',
hidden: row => !row.children?.length,
click: row => alert(`Thêm đơn vị con vào ${row.name}`),
},
{
icon: 'delete',
title: 'Xóa đơn vị lá',
color: 'error',
hidden: row => !!row.children?.length,
click: row => alert(`Xóa ${row.name}`),
},
],
},
filler: { enabled: true },
columns: [
{ field: 'name', type: 'string', title: 'Đơn vị', width: '320px', filter: { default: '' } },
{ field: 'role', type: 'string', title: 'Cấp', width: '140px' },
{ field: 'headcount', type: 'number', title: 'Số nhân sự', width: '140px', align: 'right' },
],
style: { shadow: true, maxHeight: '420px' },
}));
readonly groupOption: SdTableOption<Employee> = {
type: 'local',
items: () => EMPLOYEES,