DataGrid Selection

来源:互联网 发布:最新版广联达预算软件 编辑:程序博客网 时间:2024/06/02 04:23
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <metacharset="UTF-8">
  5. <title>DataGrid Selection - jQuery EasyUI Demo</title>
  6. <linkrel="stylesheet"type="text/css"href="../../themes/default/easyui.css">
  7. <linkrel="stylesheet"type="text/css"href="../../themes/icon.css">
  8. <linkrel="stylesheet"type="text/css"href="../demo.css">
  9. <scripttype="text/javascript"src="../../jquery.min.js"></script>
  10. <scripttype="text/javascript"src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>DataGrid Selection</h2>
  14. <divclass="demo-info">
  15. <divclass="demo-tip icon-tip"></div>
  16. <div>Choose a selection mode and select one or more rows.</div>
  17. </div>
  18. <divstyle="margin:10px0;">
  19. <ahref="#"class="easyui-linkbutton"onclick="getSelected()">GetSelected</a>
  20. <ahref="#"class="easyui-linkbutton"onclick="getSelections()">GetSelections</a>
  21. </div>
  22. <tableid="dg"class="easyui-datagrid"title="DataGrid Selection"style="width:700px;height:250px"
  23. data-options="singleSelect:true,url:'datagrid_data1.json',method:'get'">
  24. <thead>
  25. <tr>
  26. <thdata-options="field:'itemid',width:80">Item ID</th>
  27. <thdata-options="field:'productid',width:100">Product</th>
  28. <thdata-options="field:'listprice',width:80,align:'right'">List Price</th>
  29. <thdata-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
  30. <thdata-options="field:'attr1',width:250">Attribute</th>
  31. <thdata-options="field:'status',width:60,align:'center'">Status</th>
  32. </tr>
  33. </thead>
  34. </table>
  35. <divstyle="margin:10px0;">
  36. <span>Selection Mode:</span>
  37. <selectonchange="$('#dg').datagrid({singleSelect:(this.value==0)})">
  38. <optionvalue="0">Single Row</option>
  39. <optionvalue="1">Multiple Rows</option>
  40. </select>
  41. </div>
  42. <scripttype="text/javascript">
  43. function getSelected(){
  44. var row= $('#dg').datagrid('getSelected');
  45. if(row){
  46. $.messager.alert('Info', row.itemid+":"+row.productid+":"+row.attr1);
  47. }
  48. }
  49. function getSelections(){
  50. var ss=[];
  51. var rows= $('#dg').datagrid('getSelections');
  52. for(var i=0; i<rows.length; i++){
  53. var row= rows[i];
  54. ss.push('<span>'+row.itemid+":"+row.productid+":"+row.attr1+'</span>');
  55. }
  56. $.messager.alert('Info', ss.join('<br/>'));
  57. }
  58. </script>
  59. </body>
  60. </html>
0 0
原创粉丝点击