Commit 1594942f2cbe58dad042e2bbd431f0f2edc002a2
1 parent
8f48491a
itable 添加设置默认选中行的功能
Showing
2 changed files
with
40 additions
and
1 deletions
Show diff stats
src/components/table/table.vue
| @@ -548,7 +548,11 @@ | @@ -548,7 +548,11 @@ | ||
| 548 | this.data.forEach((row, index) => { | 548 | this.data.forEach((row, index) => { |
| 549 | const newRow = deepCopy(row);// todo 直接替换 | 549 | const newRow = deepCopy(row);// todo 直接替换 |
| 550 | newRow._isHover = false; | 550 | newRow._isHover = false; |
| 551 | - newRow._isChecked = false; | 551 | + if(newRow.checked){// 传checked:true 可以设置该行为默认选中状态 |
| 552 | + newRow._isChecked = newRow.checked; | ||
| 553 | + }else{ | ||
| 554 | + newRow._isChecked = false; | ||
| 555 | + } | ||
| 552 | newRow._isHighlight = false; | 556 | newRow._isHighlight = false; |
| 553 | data[index] = newRow; | 557 | data[index] = newRow; |
| 554 | }); | 558 | }); |
test/routers/table.vue
| 1 | <template> | 1 | <template> |
| 2 | <i-table border :content="self" :columns="columns7" :data="data6"></i-table> | 2 | <i-table border :content="self" :columns="columns7" :data="data6"></i-table> |
| 3 | + | ||
| 4 | + 默认选中行 | ||
| 5 | + <i-table border :content="self" :columns="columns8" :data="data8"></i-table> | ||
| 3 | </template> | 6 | </template> |
| 4 | <script> | 7 | <script> |
| 5 | export default { | 8 | export default { |
| @@ -64,6 +67,38 @@ | @@ -64,6 +67,38 @@ | ||
| 64 | age: 26, | 67 | age: 26, |
| 65 | address: '深圳市南山区深南大道' | 68 | address: '深圳市南山区深南大道' |
| 66 | } | 69 | } |
| 70 | + ], | ||
| 71 | + columns8:[ | ||
| 72 | + { | ||
| 73 | + type: 'selection', | ||
| 74 | + width: 60, | ||
| 75 | + align: 'center' | ||
| 76 | + }, | ||
| 77 | + { | ||
| 78 | + title: '名称', | ||
| 79 | + key: 'name' | ||
| 80 | + }, | ||
| 81 | + { | ||
| 82 | + title: '年龄', | ||
| 83 | + key: 'age' | ||
| 84 | + }, | ||
| 85 | + { | ||
| 86 | + title: '地址', | ||
| 87 | + key: 'address' | ||
| 88 | + } | ||
| 89 | + ], | ||
| 90 | + data8:[ | ||
| 91 | + { | ||
| 92 | + name: '王小明', | ||
| 93 | + age: 18, | ||
| 94 | + address: '北京市朝阳区芍药居', | ||
| 95 | + checked:true // 传checked 可以设置该行为默认选中状态 | ||
| 96 | + }, | ||
| 97 | + { | ||
| 98 | + name: '张小刚', | ||
| 99 | + age: 25, | ||
| 100 | + address: '北京市海淀区西二旗' | ||
| 101 | + } | ||
| 67 | ] | 102 | ] |
| 68 | } | 103 | } |
| 69 | }, | 104 | }, |