JQuery easyUI datagrid 多选下禁止选中某些行

jQuery(function($) {

		$('#dataTable').datagrid({

			//title:'菜单列表', //标题  
			method : 'post',
			iconCls : 'icon-edit', //图标  
			singleSelect : false, //多选  
			width : 'auto',
			height : inHeight, //高度  
			fitColumns : true, //自动调整各列,用了这个属性,下面各列的宽度值就只是一个比例。  
			striped : true, //奇偶行颜色不同  
			// collapsible:true,//可折叠  
			url : "xxx.html", //数据来源  
			sortName : 'id', //默认排序的列  
			sortOrder : 'desc', //倒序  
			remoteSort : true, //服务器端排序  
			pageSize : 20,
			idField : 'id', //主键字段  
			queryParams : {}, //查询条件  
			pagination : true, //显示分页  
			rownumbers : true, //显示行号  
			columns : [ [ {
				field : 'ck',
				checkbox : true,
				width : 2
			}, //显示复选框 
			{
				field : 'id', //若sortable为true则可以作为排序字段,请与数据库字段保持一致
				title : 'id',
				width : 20,
				sortable : true,
				formatter : function(value, row, index) {
					return row.id;
				}
			}, {
				field : 'start_time',
				title : '开始时间',
				width : 20,
				sortable : true,
				formatter : function(value, row, index) {
					return row.startTime;
				}

			}, {
				field : 'end_time',
				title : '结束',
				width : 20,
				sortable : true,
				formatter : function(value, row, index) {
					return row.endTime;
				}

			}

			] ],
			toolbar : [ {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					addrow();
				}
			}, '-' ],
			onLoadSuccess : function(data) {
				$('#dataTable').datagrid('clearSelections'); //一定要加上这一句,要不然datagrid会记住之前的选择状态,删除时会出问题  
				//遍历结果
				for ( var i = 0; i < data.rows.length; i++) {
					//根据status值使复选框 不可用
					if (data.rows[i].status == "1") {
						$("input[type='checkbox']")[i + 1].disabled = true;
					}

				}
			},
			onClickRow : function(rowIndex, rowData) {
				//根据status值 单击单选行不可用
				if (rowData.status == "1") {
					$('#dataTable').datagrid('unselectRow', rowIndex);

				} else {
					addrow();
				}
			},
			onDblClickRow : function(rowIndex, rowData) {
				//根据status值 双击单选行不可用
				if (rowData.status == "1") {
					$('#dataTable').datagrid('unselectRow', rowIndex);
				} else {
					addrow();
				}

			},
			onSelectAll : function(rows) {
				//根据status值  全选时某些行不选中
				$.each(rows, function(i, n) {
					if (n.status == "1") {
						$('#dataTable').datagrid('unselectRow', i);
					}
				});
			}

		});
		var p = $('#dataTable').datagrid('getPager');
		$(p).pagination({
			pageSize : 20,//每页显示的记录条数,默认为10  
			pageList : [ 10, 15, 20, 25, 30, 50 ],//可以设置每页记录条数的列表  
			beforePageText : '第',//页数文本框前显示的汉字  
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		});
	});


复选框和该行的其他列不同处理。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值