iview表格自定义多选框

本文详细介绍了如何在表格中设置短信与邮件通知的全选与多选功能,包括使用Checkbox组件进行交互,以及如何通过v-model实现数据绑定,确保用户能够灵活地选择接收通知的方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

列中定义:
{
  title: '是否短信通知',
  key: 'isSmsnotify',
  render: (h, params) => {
    return h(
      'div',
      this.$refs.myTable.$scopedSlots.smsnotifyCheckAction({ id: params.row.id })
    )
  },
  renderHeader:(h,params) => {
    return h('div',[
      h('Checkbox',{
        props:{
          value: this.isSmsnotifyCheck,
        },
        on: {
          'on-change': this.isSmsnotifyCheckclickHandler
        }
      },'是否短信通知')
    ])
  }
},{
  title: '是否邮件通知',
  key: 'isMailNotify',
  render: (h, params) => {
    return h(
      'div',
      this.$refs.myTable.$scopedSlots.mailNotifyCheckAction({ id: params.row.id })
    )
  },
  renderHeader:(h,params) => {
    return h('div',[
      h('Checkbox',{
        props:{
          value: this.isMailNotifyCheck,
        },
        on: {
          'on-change': this.isMailNotifyCheckclickHandler
        }
      },'是否邮件通知')
    ])
  }

 

表格中定义:

  <Table ref="myTable" height="250" :columns="userColumns"
         @on-selection-change="onSelectChangeUser"
         size="small"
         :data="selectData" style="margin-top: 10px;">
  <template slot="smsnotifyCheckAction" slot-scope="props">
   <span>
    <input type="checkbox" class="magic-checkbox"  :id='props.id'
           v-model="smsnotifyCheck" :value="props.id"  />
    <label :for="props.id">&nbsp;&nbsp;是</label>
     </span>
  </template>

  <template slot="mailNotifyCheckAction" slot-scope="props">
   <span>
    <input type="checkbox" class="magic-checkbox"  :id='props.id'
           v-model="mailNotifyCheck" :value="props.id"  />
    <label :for="props.id">&nbsp;&nbsp;是</label>
     </span>
  </template>

</Table>

 

方法:

isSmsnotifyCheckclickHandler:function (status) {//邮件全选多选框
  this.isSmsnotifyCheck = status
  if(status==true){
    this.smsnotifyCheck = this.tempSmsnotifyCheck
  }else{
    this.smsnotifyCheck = []
  }
},
isMailNotifyCheckclickHandler:function (status) {//短信全选多选框

  this.isMailNotifyCheck = status
  if(status==true){
    this.mailNotifyCheck = this.tempMailNotifyCheck
  }else{
    this.mailNotifyCheck = []
  }

},
### 关于iView UI架中的自定义表格列 在iView UI架中,创建带有自定义列的表格可以通过`Table`组件实现。此组件允许通过设置特定属性来自定义每一列表现形式。 对于更复杂的场景,比如需要完全控制单元格内的HTML结构或逻辑处理时,则可利用`slot`插槽机制来完成定制化需求[^1]: ```html <template> <div> <!-- 定义表格 --> <Table :columns="customColumns" :data="tableData"></Table> </div> </template> <script> export default { data () { return { // 表头配置项 customColumns: [ { title: '姓名', key: 'name' }, { title: '年龄', key: 'age' }, { title: '操作', // 自定义列标题 render: (h, params) => { // 使用render函数渲染该列的内容 return h('Button', { // 创建按钮元素 props: { type: 'primary', size: 'small' }, style: { marginRight: '5px' }, on: { click: () => this.show(params.index) } }, '详情') } } ], tableData: [{ name: '张三', age: 20 }] } }, methods: { show (index) { console.log(`点击了第${index + 1}行`) } } } </script> ``` 上述代码展示了如何向表格添加一列名为“操作”的新列,并为其提供了一个简单的按钮作为交互入口。这里的关键在于使用了`render`方法,它接收两个参数——虚拟DOM节点工厂函数`h`以及当前行的信息对象`params`。这使得开发者能够灵活地构建任意复杂度的UI控件并将其嵌入到指定位置。 值得注意的是,在某些情况下可能还需要考虑样式调整等问题以确保最终效果符合预期。此外,如果涉及到更多动态数据绑定或其他高级特性的话,建议查阅官方文档获取更多信息[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值