废话不多说,直接给大家贴代码了,具体代码如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
$(
'#table'
).bootstrapTable(
'destroy'
);
$(
'#table'
).bootstrapTable({
url:
'../data/kehulist.json'
,
uniqueId:
"id"
,
striped:
true
,
// pagination:true,
clickToSelect:
true
,
height:340,
columns: [{
field :
'state'
,
checkbox:
true
,
formatter : stateFormatter
},{
field:
'id'
,
title:
'组织编码'
,
sortable:
true
,
},{
field:
'name'
,
title:
'组织名称'
,
sortable:
true
,
}],
});
//对应的函数进行判断;
function
stateFormatter(value, row, index) {
if
(row.state ==
true
)
return
{
disabled :
false
,
//设置是否可用
checked :
true
//设置选中
};
return
value;
}
模拟后台对应的数据;
[
{
"id"
:
"1"
,
"name"
:
"金蝶软件(中国)有限公司"
,
"state"
:
false
,
//是否选中
"tel"
:
"18536552258"
},
{
"id"
:
"2"
,
"name"
:
"金蝶软件(中国)有限公司"
,
"state"
:
true
,
"tel"
:
"18536552258"
},
{
"id"
:
"3"
,
"name"
:
"金蝶软件(中国)有限公司"
,
"state"
:
false
,
"tel"
:
"18536552258"
}
]
|
以上所述是小编给大家介绍的BootStrap Table复选框默认选中功能的实现代码(从数据库获取到对应的状态进行判断是否为选中状态),希望对大家有所帮助。真是是棒棒!