2018-07-05 15:31:49
王杰
|
datagrid设置行选择默认都是多选,如果想做成只能选中一行应该怎么写?
|
wangyu
|
送你了:
var
myDataGrid
=
$
(
'#myDataGrid'
).
datagrid
({
dataSource
:
{
cols
:
[
{
name
:
'title'
,
width
:
0.99
},
// { name: 'subtitle', width: 134 },
{
name
:
'check'
,
width
:
1
,
checkbox
:
true
,
style
:
{
visibility
:
'hidden'
}
}
],
array
:
items
,
cache
:
true
,
responsive
:
true
,
// [
// {title: '00:11:12', Subtitle:'111'},
// ]
},
onSelectRow
:
function
(
rowId
,
checked
,
selections
)
{
var
data1
=
JSON
.
stringify
(
selections
[
rowId
]);
var
count1
=
Object
.
getOwnPropertyNames
(
selections
).
length
;
// console.dir('count1=' + count1);
// console.dir(Object.getOwnPropertyNames(selections)[0]);
if
(
count1
>
1
)
{
for
(
var
i
=
0
;
i
<
count1
;
i
++)
{
var
thistimerowid
=
Object
.
getOwnPropertyNames
(
selections
)[
i
];
if
(
thistimerowid
!=
rowId
)
{
this
.
checkRow
(
thistimerowid
,
false
);
};
};
thistimerowid
=
null
;
};
console
.
dir
(
this
);
console
.
dir
(
Object
.
getOwnPropertyNames
(
selections
).
length
);
console
.
log
(
'行'
,
rowId
,
checked
?
'选中了'
:
'取消选中了'
,
data1
);
data1
=
null
;
count
=
null
;
},
|
1/1