easyui datagrid 复杂表头

function initTableData(param) {
	var height = $(window).height() - 39 + "px";
	
	var colums=[[{
		"field" : "day_no",
		"title" : "日期",
		"rowspan" : 2,
		width : "8%",
		align : "center"
	},{
		"field" : "node_name",
		"title" : "城市",
		"rowspan" : 2,
		width : "8%",
		align : "center"
	},
	{
		"field" : "all_score",
		"title" : "总得分",
		"rowspan" : 2,
		width : "8%",
		align : "center"
	}, {
		"title" : "",
		"colspan" : 4,
		width : "300"
	}, {
		"title" : "",
		"colspan" : 4,
		width : "300"
	}, {
		"title" : "",
		"colspan" : 4,
		width : "300"
	} ], [ {
		"field" : "move_score",
		"title" : "得分",
		"rowspan" : 1,
		width : "8%",
		align : "center"
	}, {
		"field" : "yd_zc_score",
		"title" : "资产效益(40%)",
		"rowspan" : 1
	}, {
		"field" : "yd_yy_score",
		"title" : "运营效率(30%)",
		"rowspan" : 1
	}, {
		"field" : "yd_gz_score",
		"title" : "客户感知(30%)",
		"rowspan" : 1
	},

	{
		"field" : "broadband_score",
		"title" : "得分",
		"rowspan" : 1,
		width : "8%",
		align : "center"
	}, {
		"field" : "kd_zc_score",
		"title" : "资产效益(40%)",
		"rowspan" : 1
	}, {
		"field" : "kd_yy_score",
		"title" : "运营效率(30%)",
		"rowspan" : 1
	}, {
		"field" : "kd_gz_score",
		"title" : "客户感知(30%)",
		"rowspan" : 1
	},
	{
		"field" : "personnel_score",
		"title" : "得分",
		"rowspan" : 1,
		
		width : "8%",
	}, {
		"field" : "rc_sl_score",
		"title" : "队伍数量",
		"rowspan" : 1
	}, {
		"field" : "rc_nl_score",
		"title" : "队伍质量",
		"rowspan" : 1
	}, {
		"field" : "rc_jg_score",
		"title" : "队伍结构",
		"rowspan" : 1
	}]];
	
	$('#dg').datagrid({
		url : ROOT+"image/imageDate",
		queryParams : param,
		fit : false,
        height: height,
		fitColumns : true,
		rownumbers : true,
		pagination : true,
		checkOnSelect: false,
	    selectOnCheck: false,
		columns : colums,
		 pageNo: 1,
		   pageSize: 20,
		    pageList: [20,40,80,100,1000]
	});
}

### 实现点击表头触发 JavaScript 函数 在 EasyUIDataGrid 组件中,可以利用 `onClickCell` 或者自定义 HTML 属性来实现点击表头触发特定的 JavaScript 函数。通常情况下,为了响应表头的操作,推荐使用 jQuery 和 EasyUI 提供的 API 结合的方式。 #### 方法一:通过 onClickColumn 事件监听器 虽然 EasyUI 官方文档并没有直接提供针对表头点击的回调函数,但是可以通过扩展插件或者修改源码的方式来增加这一功能。不过更简便的做法是借助于现有的 `onClickCell` 事件并判断当前点击的是不是表头区域: ```javascript $('#dg').datagrid({ // ... other options ... onClickCell: function(index, field, value){ if ($(this).find('.datagrid-header .datagrid-cell-' + field).is(':visible')) { alert('Header of column ' + field + ' was clicked!'); } } }); ``` 这种方法依赖于 DOM 查询以确定是否点击到了头部单元格[^1]。 #### 方法二:为 th 添加 onclick 处理程序 另一种更为直观的方法是在初始化完成后手动遍历所有的 `<th>` 元素,并为其绑定点击处理逻辑: ```html <table id="tt" class="easyui-datagrid"> <!-- 表结构 --> </table> <script type="text/javascript"> $(function(){ $('#tt').datagrid(); setTimeout(function() { $('.datagrid-header-check').unbind().click(function(e) { e.stopPropagation(); // 阻止冒泡影响到整个表头 var checked = $(this).prop('checked'); // 执行全选/取消操作 var rows = $('#tt').datagrid('getRows'); for(var i=0; i<rows.length; i++){ $('#tt').datagrid((checked)?'checkRow':'uncheckRow', i); } }); // 对每一个表头添加点击事件处理器 $(".datagrid-header-row td").each(function(i){ $(this).attr("onclick", "headerClick('" + $(this).data('field') +"')"); }); }, 0); }); // 自定义 headerClick 函数用于处理不同列的行为 function headerClick(columnName){ console.log("Clicked on header:", columnName); } </script> ``` 此代码片段展示了如何动态地给每个表头分配唯一的点击事件处理器,并传递相应的参数以便区分不同的列[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

likesyour

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值