1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <meta name="keywords" content="jquery,ui,easy,easyui,web">
  5. <meta name="description" content="easyui help you build your web page easily!">
  6. <title>jQuery EasyUI Demo</title>
  7. <link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/default/easyui.css">
  8. <link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/icon.css">
  9. <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
  10. <script type="text/javascript" src="http://www.jeasyui.net/Public/js/easyui/jquery.easyui.min.js"></script>
  11. <script>
  12. function getSelected(){
  13. var row = $('#tt').datagrid('getSelected');
  14. if (row){
  15. alert('Item ID:'+row.itemid+"\nPrice:"+row.listprice);
  16. }
  17. }
  18. function getSelections(){
  19. var ids = [];
  20. var rows = $('#tt').datagrid('getSelections');
  21. for(var i=0; i<rows.length; i++){
  22. ids.push(rows[i].itemid);
  23. }
  24. alert(ids.join('\n'));
  25. }
  26. function upRow(){
  27. var row = $('#tt').datagrid('getSelected');
  28. var rowindex = $('#tt').datagrid('getRowIndex',row);
  29. //alert(rowindex);
  30. if(rowindex === 0) {return; }
  31. $('#tt').datagrid('insertRow',{index:rowindex-1,row});
  32. $('#tt').datagrid('deleteRow',rowindex+1);
  33. }
  34. function allRows(){
  35. var rows = $('#tt').datagrid('getRows');
  36. alert(rows.length);
  37. for(var i=0; i<rows.length; i++){
  38. alert(rows[i].itemid);
  39. }
  40. }
  41. </script>
  42. </head>
  43. <body>
  44. <h1>DataGrid</h1>
  45. <div style="margin-bottom:20px">
  46. <a href="#" onclick="getSelected()">GetSelected</a>
  47. <a href="#" onclick="getSelections()">GetSelections</a>
  48. <a href="#" onclick="upRow()">upRow</a>
  49. <a href="#" onclick="allRows()">all rows</a>
  50. </div>
  51. <table id="tt" class="easyui-datagrid" style="width:600px;height:250px"
  52. url="data/datagrid_data.json"
  53. data-options="singleSelect:true"
  54. title="Load Data" iconCls="icon-save" fitColumns="true">
  55. <thead>
  56. <tr>
  57. <th field="itemid" width="80">Item ID</th>
  58. <th field="productid" width="80">Product ID</th>
  59. <th field="listprice" width="80" align="right">List Price</th>
  60. <th field="unitcost" width="80" align="right">Unit Cost</th>
  61. <th field="attr1" width="150">Attribute</th>
  62. <th field="status" width="60" align="center">Stauts</th>
  63. </tr>
  64. </thead>
  65. </table>
  66. </body>
  67. </html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description" content="easyui help you build your web page easily!">
<title>jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.net/Public/js/easyui/themes/icon.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.net/Public/js/easyui/jquery.easyui.min.js"></script>
<script>
function getSelected(){
var row = $('#tt').datagrid('getSelected');
if (row){
alert('Item ID:'+row.itemid+"\nPrice:"+row.listprice);
}
}
function getSelections(){
var ids = [];
var rows = $('#tt').datagrid('getSelections');
for(var i=0; i<rows.length; i++){
ids.push(rows[i].itemid);
}
alert(ids.join('\n'));
}
    function upRow(){
var row = $('#tt').datagrid('getSelected');
var rowindex = $('#tt').datagrid('getRowIndex',row);
//alert(rowindex);
if(rowindex === 0) {return; }
$('#tt').datagrid('insertRow',{index:rowindex-1,row});
$('#tt').datagrid('deleteRow',rowindex+1);
}
function allRows(){
var rows = $('#tt').datagrid('getRows');
alert(rows.length);
for(var i=0; i&lt;rows.length; i++){
alert(rows[i].itemid);
}
}
&lt;/script&gt;

</head>

<body>

<h1>DataGrid</h1>

<div style="margin-bottom:20px">

<a href="#" onclick="getSelected()">GetSelected</a>

<a href="#" onclick="getSelections()">GetSelections</a>

<a href="#" onclick="upRow()">upRow</a>

<a href="#" onclick="allRows()">all rows</a>

</div>

<table id="tt" class="easyui-datagrid" style="width:600px;height:250px"

url="data/datagrid_data.json"

data-options="singleSelect:true"

title="Load Data" iconCls="icon-save" fitColumns="true">

<thead>

<tr>

<th field="itemid" width="80">Item ID</th>

<th field="productid" width="80">Product ID</th>

<th field="listprice" width="80" align="right">List Price</th>

<th field="unitcost" width="80" align="right">Unit Cost</th>

<th field="attr1" width="150">Attribute</th>

<th field="status" width="60" align="center">Stauts</th>

</tr>

</thead>

</table>

</body>

</html>

  1. data-options="singleSelect:true"
data-options="singleSelect:true"

实现单行选择.

参考数据:

  1. {"total":28,"rows":[
  2. {"productid":"FI-SW-01","unitcost":10.00,"status":"P","listprice":16.50,"attr1":"Large","itemid":"EST-1"},
  3. {"productid":"K9-DL-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
  4. {"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Venomless","itemid":"EST-11"},
  5. {"productid":"AV-CB-01","unitcost":92.00,"status":"P","listprice":193.50,"attr1":"Adult Male","itemid":"EST-18"}
  6. ]}
{"total":28,"rows":[
{"productid":"FI-SW-01","unitcost":10.00,"status":"P","listprice":16.50,"attr1":"Large","itemid":"EST-1"},
{"productid":"K9-DL-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
{"productid":"RP-SN-01","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Venomless","itemid":"EST-11"},
{"productid":"AV-CB-01","unitcost":92.00,"status":"P","listprice":193.50,"attr1":"Adult Male","itemid":"EST-18"}
]}

下移同理.

最新文章

  1. js 的一些知识 摘自http://img0.pconline.com.cn/Pc_intranet/1105/13/313647_7.pdf
  2. Centos下yum安装PHP
  3. maven使用阿里云仓库
  4. 程序员定制的中州韵(rime)windows版(小狼毫)微软双拼输入法
  5. 追访现代主流程序员的家庭事业观---禅宗派程序员KUROKY
  6. HDU 4638 Group ★(树状数组)
  7. js 乱码解决方案
  8. 解题报告 HDU1087 Super Jumping! Jumping! Jumping!
  9. Android开发系列之屏幕密度和单位转换
  10. Struts1文件上传、单文件、多文件上传【Struts1】
  11. 【Egret】里使用iframe标签达到内嵌多个web界面
  12. nginx启动停止
  13. Android自定义控件及自定义属性
  14. MySQL性能调优——锁定机制与锁优化分析
  15. 正则表达式判断QQ号格式是否正确
  16. PHP 图片验证码验证
  17. Linux下的进程类别(内核线程、轻量级进程和用户进程)--Linux进程的管理与调度(四)
  18. IOS 数据存储之 FMDB 详解
  19. 【SPL标准库专题(1)】 SPL简介
  20. BZOJ2738:矩阵乘法——题解

热门文章

  1. 容器_JDK源码分析_自己简单实现ArrayList容器
  2. .NetCore~Json代替了Xml
  3. 基于 WebRTC 技术的实时通信服务开发实践
  4. 计算 x y 的最近值
  5. c/c++ SQLite3的常用使用方法;
  6. spring加载异常
  7. form表单提交图片禁止跳转
  8. ubuntu14.04下编译安装ambari-2.4.2.0
  9. xmake v2.1.5版本正式发布,大量新特性更新
  10. Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: &quot;((()))&quot;, &quot;(()())&quot;, &quot;(())()&quot;, &quot;()(())&quot;, &quot;()()()&quot;