Vue 表格多选批量编辑

**

以下为Vue部分

**

   handleSelectionChange(val) {
            this.multipleSelection = val;
        },
 var ids = []
            this.multipleSelection.forEach(row => {
            ids.push(row.id)//将选中行的id进行循环遍历存入自定义的ids数组中
    })

  
                this.form2 = {
                    idArr:ids,//将存放id的数组传给后台新建的一个idArr字段
                    testmachine:_self.testmachine_input,
                    testtime:_self.testtime_input,
                    jobnum:_self.jobnum,
                    moduser:_self.userId,
                    testresult:_self.form2.testresult2
                }
                
  this.$http({
                        method: 'post',
                        url: '/SerialnumberCheckinfoLink/UpdateSerialnumberCheckinfoLinkAll/',
                        data: _self.form2
                    })

插入element ui官方的自带属性

分别插入 :row-key="(row)=>{ return row.id}", :reserve-selection=“true” 属性为分页自动保留多选选中状态

以下为c#部分

 public int [] idArr { get; set; }//另外再定义的一个存放前端传来的id数组(就是前面的ids)

业务层方法


        public VmWebResponse<SerialnumberCheckinfoLink> UpdateSerialnumberCheckinfoLinkAll(SerialnumberCheckinfoLink serialnumberCheckinfoLink)
        {
            try
            {
                SerialnumberCheckinfoLinkDao serialnumberCheckinfoLinkDao = new SerialnumberCheckinfoLinkDao(conn);
                //List<SerialnumberCheckinfoLink> serialnumberCheckinfoLinklist = serialnumberCheckinfoLinkDao.GetById(serialnumberCheckinfoLink.id);

                for (int i = 0; i < serialnumberCheckinfoLink.idArr.Length; i++)
                {
                    serialnumberCheckinfoLink.moddate = DateTime.Now;
                    serialnumberCheckinfoLink.id = serialnumberCheckinfoLink.idArr[i];//循环每次传入的id数组赋值给id去数据库查找
                    serialnumberCheckinfoLinkDao.Updateall(serialnumberCheckinfoLink);
                }

             
                return new VmWebResponse<SerialnumberCheckinfoLink>(serialnumberCheckinfoLink);
            
            }
            catch (Exception ex)
            {
                return new VmWebResponse<SerialnumberCheckinfoLink>(1, ex);
            }
        }
在Ant Design Vue中,可以使用`rowSelection`属性来实现表格多选功能。具体步骤如下: 1. 在表格组件中添加`rowSelection`属性,并设置`type`为`checkbox`,表示使用复选框来进行多选。 2. 在`rowSelection`属性中,设置`selectedRowKeys`为一个数组,用于存储当前选中的行的`key`值。 3. 在表格的列定义中,添加一列用于显示复选框,并设置`customRender`属性为一个函数,用于自定义复选框的显示和选中状态。 下面是一个示例代码: ```vue <template> <a-table :columns="columns" :data-source="dataSource" :row-selection="rowSelection"></a-table> </template> <script> export default { data() { return { dataSource: [ { id: 1, name: 'John', age: 18 }, { id: 2, name: 'Mike', age: 22 }, { id: 3, name: 'Lucy', age: 20 } ], selectedRowKeys: [] } }, computed: { rowSelection() { return { type: 'checkbox', selectedRowKeys: this.selectedRowKeys, onChange: this.handleSelectChange } }, columns() { return [ { title: 'ID', dataIndex: 'id' }, { title: 'Name', dataIndex: 'name' }, { title: 'Age', dataIndex: 'age' }, { title: 'Select', customRender: (text, record) => { const isSelected = this.selectedRowKeys.includes(record.id) return <a-checkbox checked={isSelected} onChange={() => this.handleRowSelect(record)}></a-checkbox> } } ] } }, methods: { handleRowSelect(record) { const { id } = record const index = this.selectedRowKeys.indexOf(id) if (index > -1) { this.selectedRowKeys.splice(index, 1) } else { this.selectedRowKeys.push(id) } }, handleSelectChange(selectedRowKeys) { this.selectedRowKeys = selectedRowKeys } } } </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值