easyui datagrid单击单元格选择此列
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了easyui datagrid单击单元格选择此列,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2063字,纯文字阅读大概需要3分钟。
内容图文
示例代码实现单击jquery easyui datagrid的单元格时,取消datagrid默认选中高亮此行的样式,改为选中单击的单元格所在的列,高亮此列上的所有单元格。可以配置全局single变量,只允许同时选中一列,如果不配置则默认可以选中多列。单击选中的列会取消选中高亮样式。
源代码如下,示例测试的easyui版本为1.3.5,如果没有效果,自己用firebug或者chrome开发工具找到数据容器的样式,修改代码对应的选择器。
< table class ="easyui-datagrid" title ="jquery easyui datagrid单击单元格选择此列" style ="width:700px;height:250px" data-options ="singleSelect:true,collapsible:true,url:‘datagrid_data1.json‘,method:‘get‘" id ="dg" > < thead > < tr > < th data-options ="field:‘itemid‘,width:80" >Item ID</th><th data-options="field:‘productid‘,width:100">Product</th><th data-options="field:‘listprice‘,width:80,align:‘right‘">List Price</th><th data-options="field:‘unitcost‘,width:80,align:‘right‘">Unit Cost</th><th data-options="field:‘attr1‘,width:250">Attribute</th><th data-options="field:‘status‘,width:60,align:‘center‘">Status</th></tr></thead></table><style> .td-select{background:#FBEC88}/*td高亮样式*/</style><script>//var single = true;//配置是否只能同时选择一行 $(function () { $(‘#dg‘).datagrid({ onClickCell: function (rowIndex, field, value) { var me =this; setTimeout(function () { $(me).datagrid(‘unselectRow‘, rowIndex) }, 1); //取消easyui的默认行选择样式,注意要延时执行,要不无法取消默认样式 }, onLoadSuccess: function () { //给内容table增加单元格click事件,获取单元格所在列下标进行相关DOM处理操作 $(this).closest(‘div.datagrid-view‘).find(‘div.datagrid-body td‘).click(function () { var cellIndex =this.cellIndex, add =this.className.indexOf(‘td-select‘) ==-1; if (window.single ===true||typeof window.single ==‘number‘) {//是否为单选if (window.single ===true) single = cellIndex; elseif (single != cellIndex) { $(this).closest(‘div.datagrid-body‘).find(‘td.td-select‘).removeClass(‘td-select‘); single = cellIndex; } } $(this).closest(‘div.datagrid-body‘).find(‘tr‘).each(function () {//遍历数据行找到对应的列进行高亮操作 $(this).find(‘td‘).eq(cellIndex)[add ?‘addClass‘ : ‘removeClass‘](‘td-select‘); }); }); } }); }); </script>
原文:http://www.cnblogs.com/longshiyVip/p/4925413.html
内容总结
以上是互联网集市为您收集整理的easyui datagrid单击单元格选择此列全部内容,希望文章能够帮你解决easyui datagrid单击单元格选择此列所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。