一:datagrid列表
//绚染列表
$('#tt').datagrid({
title:"系统管理员列表",
iconCls:"icon-save",//图标
url:'xxxxx.action',
width:"100%",
height:"auto",
nowrap: false, //默认true,设置为 true,则把数据显示在一行里。
striped: true, //设置为 true,则把行条纹化。(即奇偶行使用不同背景色)
border: true, //边框
collapsible:false,//是否可折叠的
fitColumns:true,//设置为 true,则会自动扩大或缩小列的尺寸以适应网格的宽度并且防止水平滚动。
fixed:true,//设置为 true,则当 'fitColumns' 设置为 true 时放置调整宽度。
singleSelect:false,//是否单选
pagination:true,//分页控件
rownumbers:true,//显示行号
queryParams: form2Json("searchform"),//多条件查询关键之处
remoteSort:false,//默认true,定义是否从服务器排序数据。
checkOnSelect:false,//点击该行数据不会选中复选框,只有对准复选框点击才能选中
//sortName: 'code',
//idField:'fldId',//根据什么参数进行排序
//sortOrder: 'desc',//排序
//pageSize: 15,//默认初始每页显示数
//pageList: [15, 20, 30, 50],//每页显示数的选择框
frozenColumns:[[ {field:'ck',checkbox:true} ]],//多选框,位置固定在最左边
columns:[
[
{field: "xxx_name", title: "姓名", width:"20%", align: "center"},//field后台返回数据的name名称, title标题名称 ,width宽度,align字体位置
{field: "xxx_account", title: "账号", width:"20%", align: "center"},
{field: "xxx_password", title: "密码", width: "10%", align: "center"},
{field: "xxx_sex", title: "性别", width: "10%", align: "center"},
{field: "xxx_registration_time", title: "注册时间", width: "20%", align: "center"},
{field: "xxx",title:"操作",width:fixWidth(0.169),align:"center",
formatter:function(value,row,index){ //value:字段的值。 row:当前行的所有数据row点出具体的数据,比如要admin_id就是row.admin_id就可以用。index:行的索引,就是当前行的行号。
var btn = "<a href='javascript:void(0)' class='editcls' onclick='showYW("+value+")' >授权</a></div>";
return btn;
}
}
]
],//显示数据库查询出来的数据
toolbar: [{
text: '添加',
iconCls: 'icon-add',
handler: function() {
openDialog("add");
}
}, '-', {
text: '修改',
iconCls: 'icon-edit',
handler: function() {
openDialog("edit");
}
}, '-',{
text: '删除',
iconCls: 'icon-remove',
handler: function(){
delAppInfo();
}
}], //添加按钮
});
二:获取方式
取得选中行数据,这里只获取一行,如果选择了多行也只返回第一次点击的哪一行的事数据:
var row = $('#tt').datagrid('getSelected');
if (row){
alert("Item ID:"+row.itemid+"Price:"+row.listprice);
}
取的选中行数据,这里选的数据是所有行的数据,选择多少行就返回多少行的数据
var ids = [];
var rows = $('#tt').datagrid('getSelections');
for(var i=0; i<rows.length; i++){
ids.push(rows[i].itemid);
}
alert(ids.join(''));