easyui中treegrid复选框不能复选的问题

风行傲天 2013-01-14 10:18:17


点击复选框时只能单选,不知道什么问题,求大侠们指教

源码

//设置treegrid自适应
$(window).resize(function(){
$('#treeGrid').treegrid('resize', {
width: '100%'
})
});

//js获取项目根路径,如: http://localhost:8088/jquery
function getRootPath(){
//获取当前网址,如: http://localhost:8088/jquery/easyui/login.jsp
var curWwwPath = window.document.location.href;
//获取主机地址之后的目录,如: jquery/easyui/login.jsp
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8088
var localhostPaht = curWwwPath.substring(0, pos);
//获取带"/"的项目名,如:/jquery
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
return (localhostPaht + projectName);
}

var treeGrid;
$(function(){
InitTreeGrid();
});

/**
* 初始化treegrid
*/
function InitTreeGrid(){

treeGrid = $('#treeGrid').treegrid({
url: getRootPath() + '/treeGrid',
title: '编辑treeGrid',
rownumbers: true,
idField: 'id',
treeField: 'text',
width: '100%',
fitColumns: true,
columns: [[{
title: '序号',
field: 'id',
align: 'center',
//复选框
checkbox: true
}, {
title: '名称',
field: 'text',
width: 280
}, {
title: '全名',
field: 'fullname',
width: 280,
align: 'right'
}, {
title: '英文名',
field: 'nameen',
width: 280
}, {
title: '级别',
field: 'level',
width: 280
}, {
title: '状态',
field: 'status',
width: 280
}]],
toolbar: [{
id: 'idAdd',
text: '增加',
iconCls: 'icon-add',
plain: 'true',
//按钮事件
handler: function(){

}
}, '-', {
id: 'idDelete',
text: '删除',
//disabled: true,
iconCls: 'icon-remove',
//按钮事件
handler: function(){

}
}, '-', {
id: 'idEdit',
text: '修改',
iconCls: 'icon-edit',
//disabled: true,
handler: function(){
}
}, '-', {
id: 'idSave',
text: '保存',
iconCls: 'icon-save',
//disabled: true,
handler: function(){
}
}, '-', {
id: 'idCancle',
text: '取消编辑',
iconCls: 'icon-undo',
//disabled: true,
handler: function(){
}
}, '-'],


});
}


/**
* 修改树
*/
function modifyTree(){

}

/**
* 删除节点
*/
function removeTree(){

//获取选中的行数
var rows = treeGrid.treegrid('getSelections');
if (rows.length > 0) {
//存放选中行的id
var ids = [];
for (var i = 0; i < rows.length; i++) {
ids.push(rows[i].oid);
}
}
}
...全文
3226 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
_下划线开头 2014-01-09
  • 打赏
  • 举报
回复
楼主,你的columns里的第一个{}后面都没有,确定你的可以?
风行傲天 2013-04-12
  • 打赏
  • 举报
回复
解决了,是这样做的
columns: [[{
field: 'oid',
title: '选择',
width: 20,
formatter: function(value, rowData, rowIndex){
return '<input type="radio" name="selectRadio" id="selectRadio"' + rowIndex + ' value="' + rowData.oid + '" />';
}
}


onLoadSuccess: function(data){
//加载完毕后获取所有的checkbox遍历
if (data.rows.length > 0) {
//循环判断操作为新增的不能选择
for (var i = 0; i < data.rows.length; i++) {
//根据operate让某些行不可选
if (data.rows[i].operate == "false") {
$("input[type='radio']")[i].disabled = true;
}
}
}
},
onClickRow: function(rowIndex, rowData){
//加载完毕后获取所有的checkbox遍历
var radio = $("input[type='radio']")[rowIndex].disabled;
//如果当前的单选框不可选,则不让其选中
if (radio != true) {
//让点击的行单选按钮选中
$("input[type='radio']")[rowIndex].checked = true;
}
else {
$("input[type='radio']")[rowIndex].checked = false;
}
}

就解决了
如图


可以实现让某些行不可选的效果
  • 打赏
  • 举报
回复
LZ的问题解决了没?
风行傲天 2013-04-01
  • 打赏
  • 举报
回复
我想要的是显示单选框,设置singleSelect:false只是复选框单选效果,不是我想要的
sheep212 2013-02-21
  • 打赏
  • 举报
回复
singleSelect:false, //是否单选

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧