rayyy-vue-table-components 2.0.51 → 2.0.53

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
@@ -358,6 +358,137 @@ const handleSelectionChange = (selection: Product[]) => {
358
358
  ```
359
359
  </details>
360
360
 
361
+ <details>
362
+ <summary>展開行用法</summary>
363
+
364
+ ```vue
365
+ <template>
366
+ <BaseTable
367
+ :data="tableData"
368
+ :columns="columns"
369
+ show-expand
370
+ preserve-expanded
371
+ >
372
+ <template #expand="{ row }">
373
+ <div class="m-4">
374
+ <p>State: {{ row.state }}</p>
375
+ <p>City: {{ row.city }}</p>
376
+ <el-table :data="row.family" border>
377
+ <el-table-column label="Name" prop="name" />
378
+ <el-table-column label="State" prop="state" />
379
+ </el-table>
380
+ </div>
381
+ </template>
382
+ </BaseTable>
383
+ </template>
384
+
385
+ <script setup lang="ts">
386
+ import { ref } from 'vue'
387
+ import { BaseTable } from 'rayyy-vue-table-components'
388
+ import type { TableColumn } from 'rayyy-vue-table-components'
389
+
390
+ interface Family {
391
+ name: string
392
+ state: string
393
+ }
394
+
395
+ interface UserWithFamily {
396
+ id: number
397
+ name: string
398
+ state: string
399
+ city: string
400
+ family: Family[]
401
+ }
402
+
403
+ const tableData = ref<UserWithFamily[]>([
404
+ {
405
+ id: 1,
406
+ name: '張三',
407
+ state: '台北',
408
+ city: '信義區',
409
+ family: [
410
+ { name: '張小明', state: '台北' },
411
+ { name: '張小華', state: '新北' },
412
+ ],
413
+ },
414
+ ])
415
+
416
+ const columns: TableColumn<UserWithFamily>[] = [
417
+ { prop: 'id', label: 'ID', width: 80 },
418
+ { prop: 'name', label: '姓名' },
419
+ { prop: 'state', label: '縣市' },
420
+ { prop: 'city', label: '區域' },
421
+ ]
422
+ </script>
423
+ ```
424
+ </details>
425
+
426
+ <details>
427
+ <summary>樹形資料與懶加載用法</summary>
428
+
429
+ ```vue
430
+ <template>
431
+ <BaseTable
432
+ :data="treeData"
433
+ :columns="columns"
434
+ row-key="id"
435
+ :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
436
+ :lazy="true"
437
+ :load="loadChildren"
438
+ />
439
+ </template>
440
+
441
+ <script setup lang="ts">
442
+ import { ref } from 'vue'
443
+ import { BaseTable } from 'rayyy-vue-table-components'
444
+ import type { TableColumn } from 'rayyy-vue-table-components'
445
+
446
+ interface TreeItem {
447
+ id: string
448
+ name: string
449
+ department: string
450
+ hasChildren?: boolean
451
+ children?: TreeItem[]
452
+ }
453
+
454
+ const treeData = ref<TreeItem[]>([
455
+ {
456
+ id: 'dept-tech',
457
+ name: '技術部',
458
+ department: '技術部',
459
+ children: [{ id: 'u-101', name: '林工程師', department: '技術部' }],
460
+ },
461
+ {
462
+ id: 'dept-product',
463
+ name: '產品部',
464
+ department: '產品部',
465
+ hasChildren: true,
466
+ },
467
+ ])
468
+
469
+ const columns: TableColumn<TreeItem>[] = [
470
+ { prop: 'name', label: '名稱' },
471
+ { prop: 'department', label: '部門' },
472
+ ]
473
+
474
+ const loadChildren = (
475
+ row: TreeItem,
476
+ _treeNode: unknown,
477
+ resolve: (data: TreeItem[]) => void,
478
+ ) => {
479
+ // 模擬 API
480
+ setTimeout(() => {
481
+ if (row.id === 'dept-product') {
482
+ resolve([{ id: 'u-201', name: '蔡產品', department: '產品部' }])
483
+ return
484
+ }
485
+ resolve([])
486
+ }, 500)
487
+ }
488
+ </script>
489
+ ```
490
+ </details>
491
+
361
492
  #### SortTable - 排序表格
362
493
 
363
494
  支援多列排序的高級表格組件。
@@ -1179,8 +1310,17 @@ const handleColumnSubmit = (newColumns: TableColumn<User>[]) => {
1179
1310
  | `showOverFlowTooltip` | `boolean` | `false` | 是否顯示溢出提示 |
1180
1311
  | `summaryMethod` | `SummaryMethod<T>` | - | 合計行計算方法 |
1181
1312
  | `baseTableRowClassName` | `RowClassNameGetter<T>` | - | 行樣式類名函數 |
1313
+ | `showIndex` | `boolean` | `false` | 是否顯示索引列 |
1314
+ | `showExpand` | `boolean` | `false` | 是否顯示展開列 |
1315
+ | `rowKey` | `string \| ((row: T) => string)` | - | 行資料的唯一鍵(樹形資料與懶加載建議必填) |
1316
+ | `treeProps` | `{ children?: string; hasChildren?: string; checkStrictly?: boolean }` | `{ children: 'children', hasChildren: 'hasChildren' }` | 樹形資料欄位配置 |
1317
+ | `defaultExpandAll` | `boolean` | `false` | 是否預設展開所有節點 |
1318
+ | `expandRowKeys` | `string[]` | `[]` | 指定展開節點 keys |
1319
+ | `lazy` | `boolean` | `false` | 是否啟用懶加載子節點 |
1320
+ | `load` | `(row, treeNode, resolve) => void` | - | 懶加載函式 |
1182
1321
  | `showCheckBtn` | `boolean` | `false` | 是否顯示查看按鈕 |
1183
1322
  | `showEditBtn` | `boolean` | `false` | 是否顯示編輯按鈕 |
1323
+ | `preserveExpanded` | `boolean` | `false` | 資料更新時是否保留已展開狀態 |
1184
1324
 
1185
1325
  #### Events
1186
1326
 
@@ -1197,8 +1337,7 @@ const handleColumnSubmit = (newColumns: TableColumn<User>[]) => {
1197
1337
 
1198
1338
  | 插槽名 | 參數 | 說明 |
1199
1339
  |--------|------|------|
1200
- | `empty` | - | 空數據時的內容 |
1201
- | `append` | - | 插入至表格最後一行之後的內容 |
1340
+ | `expand` | `{ row: T, $index: number }` | 展開行的自訂內容(需搭配 `showExpand`) |
1202
1341
 
1203
1342
  ---
1204
1343
 
@@ -1335,8 +1474,17 @@ type ComponentSize = 'default' | 'small' | 'large'
1335
1474
  | `showOverFlowTooltip` | `boolean` | `false` | 是否顯示溢出提示 |
1336
1475
  | `summaryMethod` | `SummaryMethod<T>` | - | 合計行計算方法 |
1337
1476
  | `sortTableRowClassName` | `RowClassNameGetter<T>` | - | 行樣式類名函數 |
1477
+ | `showIndex` | `boolean` | `false` | 是否顯示索引列 |
1478
+ | `showExpand` | `boolean` | `false` | 是否顯示展開列 |
1479
+ | `rowKey` | `string \| ((row: T) => string)` | - | 行資料的唯一鍵(樹形資料與懶加載建議必填) |
1480
+ | `treeProps` | `{ children?: string; hasChildren?: string; checkStrictly?: boolean }` | `{ children: 'children', hasChildren: 'hasChildren' }` | 樹形資料欄位配置 |
1481
+ | `defaultExpandAll` | `boolean` | `false` | 是否預設展開所有節點 |
1482
+ | `expandRowKeys` | `string[]` | `[]` | 指定展開節點 keys |
1483
+ | `lazy` | `boolean` | `false` | 是否啟用懶加載子節點 |
1484
+ | `load` | `(row, treeNode, resolve) => void` | - | 懶加載函式 |
1338
1485
  | `showCheckBtn` | `boolean` | `false` | 是否顯示查看按鈕 |
1339
1486
  | `showEditBtn` | `boolean` | `false` | 是否顯示編輯按鈕 |
1487
+ | `preserveExpanded` | `boolean` | `false` | 資料更新時是否保留已展開狀態 |
1340
1488
 
1341
1489
  #### Events
1342
1490
 
@@ -1348,6 +1496,13 @@ type ComponentSize = 'default' | 'small' | 'large'
1348
1496
  | `click:cell` | `column: TableColumn<T>, row: T` | 單元格點擊時觸發 |
1349
1497
  | `sort-change` | `sortInfo: SortInfo<T>` | 排序變更時觸發 |
1350
1498
 
1499
+ #### Slots
1500
+
1501
+ | 插槽名 | 參數 | 說明 |
1502
+ |--------|------|------|
1503
+ | `firstButton` | - | 第一個按鈕插槽 |
1504
+ | `expand` | `{ row: T, $index: number }` | 展開行的自訂內容(需搭配 `showExpand`) |
1505
+
1351
1506
  ---
1352
1507
 
1353
1508
  ### TitleTable
@@ -1367,8 +1522,17 @@ type ComponentSize = 'default' | 'small' | 'large'
1367
1522
  | `showOverFlowTooltip` | `boolean` | `false` | 是否顯示溢出提示 |
1368
1523
  | `summaryMethod` | `SummaryMethod<T>` | - | 合計行計算方法 |
1369
1524
  | `titleTableRowClassName` | `RowClassNameGetter<T>` | - | 行樣式類名函數 |
1525
+ | `showIndex` | `boolean` | `false` | 是否顯示索引列 |
1526
+ | `showExpand` | `boolean` | `false` | 是否顯示展開列 |
1527
+ | `rowKey` | `string \| ((row: T) => string)` | - | 行資料的唯一鍵(樹形資料與懶加載建議必填) |
1528
+ | `treeProps` | `{ children?: string; hasChildren?: string; checkStrictly?: boolean }` | `{ children: 'children', hasChildren: 'hasChildren' }` | 樹形資料欄位配置 |
1529
+ | `defaultExpandAll` | `boolean` | `false` | 是否預設展開所有節點 |
1530
+ | `expandRowKeys` | `string[]` | `[]` | 指定展開節點 keys |
1531
+ | `lazy` | `boolean` | `false` | 是否啟用懶加載子節點 |
1532
+ | `load` | `(row, treeNode, resolve) => void` | - | 懶加載函式 |
1370
1533
  | `showCheckBtn` | `boolean` | `false` | 是否顯示查看按鈕 |
1371
1534
  | `showEditBtn` | `boolean` | `false` | 是否顯示編輯按鈕 |
1535
+ | `preserveExpanded` | `boolean` | `false` | 資料更新時是否保留已展開狀態 |
1372
1536
 
1373
1537
  #### Events
1374
1538
 
@@ -1380,6 +1544,14 @@ type ComponentSize = 'default' | 'small' | 'large'
1380
1544
  | `click:cell` | `column: TableColumn<T>, row: T` | 單元格點擊時觸發 |
1381
1545
  | `sort-change` | `sortInfo: SortInfo<T>` | 排序變更時觸發 |
1382
1546
 
1547
+ #### Slots
1548
+
1549
+ | 插槽名 | 參數 | 說明 |
1550
+ |--------|------|------|
1551
+ | `tableSearch` | - | 搜尋區域插槽 |
1552
+ | `editBtn` | - | 編輯按鈕區域插槽 |
1553
+ | `expand` | `{ row: T, $index: number }` | 展開行的自訂內容(需搭配 `showExpand`) |
1554
+
1383
1555
  ---
1384
1556
 
1385
1557
  ### SearchBar
@@ -1925,7 +2097,16 @@ src/
1925
2097
 
1926
2098
  查看 [CHANGELOG.md](./CHANGELOG.md) 了解詳細的版本更新記錄。
1927
2099
 
1928
- #### 最新更新 (v2.0.22)
2100
+ #### 最新更新 (v2.0.52)
2101
+
2102
+ **🗂️ 表格組件增強**
2103
+ - ✅ 新增展開行功能:`showExpand` prop + `expand` slot,支援自訂展開內容
2104
+ - ✅ 新增 `preserveExpanded` prop,資料更新時可保留已展開狀態
2105
+ - ✅ 新增 `showIndex` prop,支援索引列顯示
2106
+ - ✅ BaseTable、SortTable、TitleTable 三個表格組件皆支援上述功能
2107
+ - ✅ 新增 `BaseTableSlots`、`SortTableSlots`、`TitleTableSlots` 類型定義
2108
+
2109
+ #### v2.0.22
1929
2110
 
1930
2111
  **🌐 國際化 (i18n) 支持**
1931
2112
  - ✅ 新增完整的國際化支持,支援繁體中文 (zh-TW) 和英文 (en-US)