easyui datagrid editor checkbox 选中

在使用easyui datagrid的编辑功能时,遇到编辑行中的checkbox未正确显示已选中状态。当数据中的布尔值为true时,checkbox未自动勾选。为解决这个问题,需要将数据中的布尔值转换为字符串,例如将`"status": true`改为`"status": "true"`,以确保在编辑模式下checkbox能正确反映原始状态。

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

easyui datagrid editor checkbox 选中


在前台如果使用easyui的datagrid
需要编辑行时遇到checkbox无法还原选中事件时
easyUI的datagrid中,列的checkbox这样设置:
{field:'status',title:'Status',width:50,align:'center',  
    editor:{  
        type:'checkbox',  
        options:{  
            on: "true",  
            off: "false"  
        }  
    }  
},  

数据:
{"total":28,"rows":[  
    {"productid":"FI-SW-01","unitcost":10.00,"status":true,"listprice":16.50,"attr1":"Large","itemid":"EST-1"},  
    {"productid":"K9-DL-01","unitcost":12.00,"status":true,"listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},  
    {"productid":"RP-SN-01","unitcost":12.00,"status":true,"listprice":18.50,"attr1":"Venomless","itemid":"EST-11"}  
]}  

这样子就有个问题:

当datagrid里的行处于编辑状态时,checkbox并未能自动带上应有的值,比如本来对应是true,但当checkbox出现时,并没有自动勾选!造成很不好的后果:编辑一次,如果不手动对这个checkbox再打钩一次,那么原本是true,现在就变成了 false !什么毛病。

对应办法是将数据里的布尔值变为字符串:"status":true ==> "status":"true"

{"total":28,"rows":[  
    {"productid":"FI-SW-01","unitcost":10.00,"status":"true","listprice":16.50,"attr1":"Large","itemid":"EST-1"},  
    {"productid":"K9-DL-01","unitcost":12.00,"status":"true","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},  
    {"productid":"RP-SN-01","unitcost":12.00,"status":"true","listprice":18.50,"attr1":"Venomless","itemid":"EST-11"}  
]}  

如果无法更改数据源,但是又需要还原时,就需要这样做了:
{field:'status',title:'Status',width:50,align:'center',  
    editor:{  
        type:'checkbox',  
        options:{  
            on: "1",  
            off: "0"  
        }  
    }  
},  

这样就完美的解决了你的问题

当然,如果你的数据  本身就是加了引号的"true"和"false"

那就只需要向最上面那样就行了..



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值