问题描述
<div id="myDatagrid""> <table id="datagridID" class="easyui-datagrid" data-options="pagination:true,rownumbers:true, fitColumns:true,url:'...',loadMsg:'load data...'"> <thead> <tr> <th data-options="field:'checkBox',checkbox:true"></th> </tr> </thead> </table></div>代码如上所示,我想让checkbox初始化就为全部选中,不知道应该怎么做?谢谢
解决方案
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>CheckBox Selection on DataGrid - jQuery EasyUI Demo</title><link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"><link rel="stylesheet" type="text/css" href="../../themes/icon.css"><link rel="stylesheet" type="text/css" href="../demo.css"><script type="text/javascript" src="../../jquery-1.8.0.min.js"></script><script type="text/javascript" src="../../jquery.easyui.min.js"></script><script>function selectAllBox(){$('#dg').datagrid('selectAll'); }</script></head><body><h2>CheckBox Selection on DataGrid</h2><div class="demo-info"><div class="demo-tip icon-tip"></div><div>Click the checkbox on header to select or unselect all selections.</div></div><div style="margin:10px 0;"></div><table id="dg" class="easyui-datagrid" title="CheckBox Selection on DataGrid" style="width:700px;height:250px"data-options="rownumbers:true,url:'../datagrid/datagrid_data1.json',onLoadSuccess:selectAllBox"><thead><tr><th data-options="field:'ck',checkbox:true"></th><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:220">Attribute</th><th data-options="field:'status',width:60,align:'center'">Status</th></tr></thead></table></body></html>
解决方案二:
这个好像没有属性的配置吧 不过自己用js去空间也相当的简单的
解决方案三:
{field:'ck',checkbox:true},这个换成下面的写法就行了。从后台取数据再确定是否选中,则判断value值即可。{field:'ck',formatter:function(value,rec){ return '<input type="checkbox" name="xxx" checked="true" value='+value+'>'; }},