标签:des style blog http color io os ar java
关于easyui,之前只是听说过了解一点点,到这边上班之后发现他们用的极多,然后作为新人被安排的一些简单的任务里也有用到它的。没办法,硬着头皮上吧,一边对着官网上的demo,一边对着手册,一边摸索着做呗。首先看效果图
相关代码如下(只摘的部分供参考,不能运行的):
$(‘#tt‘).datagrid({
nowrap: false,
striped: true,
remoteSort: false,
singleSelect: true,
fitColumns: true,
pageSize: 25,
pageList: [25, 35, 45, 55],
title: "商家信息",
toolbar: ‘#toors‘,
loadMsg: ‘加载中...‘,
// onDblClickRow: function (rowIndex, rowData) {
// getsub(rowIndex, rowData, callback);
// var ExpandRow = $("#ExpandRow").val();
// if (ExpandRow != ‘‘) {
// $(‘#tt‘).datagrid("expandRow", ExpandRow);
// }
// $("#ExpandRow").val(rowIndex); ;
// },
url: ‘../ashx/SellerManager.ashx?type=GetSellerList&se_property=0‘,
columns: [[
{ field: ‘SE_NAME‘, title: ‘商家名称‘, width: $(this).width() * 0.13, formatter: function (value, row, index) {
return "<a href=‘http://seller.jukelai.cn/AStation/?suname=" + row.USERNAME + "&supwd=" + row.UPASSWORD + "‘ target=‘_blank‘>" + row.SE_NAME + "</a>";
}
},
{ field: ‘USERNAME‘, title: ‘用户名‘, width: $(this).width() * 0.1 },
{ field: ‘SE_TYPE‘, title: ‘商家类型‘, width: $(this).width() * 0.1 },
{ field: ‘PROVINCES‘, title: ‘所在地‘, width: $(this).width() * 0.1, formatter: function (value, row, index) {
return row.PROVINCES + ‘-‘ + row.CITY + "-" + row.COUNTY;
}
},
{ field: ‘SE_CONTACT‘, title: ‘联系人‘, width: $(this).width() * 0.1 },
{ field: ‘SE_PHONE‘, title: ‘联系电话‘, width: $(this).width() * 0.1 },
{ field: ‘SE_EQUIPMENTCOUNT‘, title: ‘设备数量‘, width: $(this).width() * 0.1 },
{ field: ‘SE_URL‘, title: ‘网址‘, width: $(this).width() * 0.1 },
{ field: ‘SE_BUSINESSAREA‘, title: ‘营业面积‘, width: $(this).width() * 0.1 },
{ field: ‘SE_PROPERTY‘, title: ‘性质‘, width: $(this).width() * 0.1, formatter: function (value, row, index) {
if (row.SE_PROPERTY == 0) {
return ‘总店‘;
}
else {
return ‘分店‘;
}
}
}
]],
onClickRow: function (rowIndex, rowData) {
if (childbody != null) {
childbody.datagrid(‘unselectAll‘);
}
},
pagination: true,
onLoadSuccess: function (data) {
if (data.total == 0) {
console.info(‘进入无数据‘);
var body = $(this).data().datagrid.dc.body2;
console.info("body:%f", body);
body.find(‘table tbody‘).append(‘<tr><td width="‘ + body.width() + ‘" style="height: 25px; text-align: center; color:Red">抱歉,没有查询到数据</td></tr>‘);
}
}
});
var ExpandRow = null;
$(‘#tt‘).datagrid({
view: detailview,
detailFormatter: function (index, row) {
return ‘<div style="padding:3px" id="ddv-"‘ + index + ‘><table class="ddv"></table></div>‘;
},
onExpandRow: function (index, row) {
getsub(index, row, callback);
collapserow(index);
//$(‘#tt‘).datagrid(‘reload‘);
}
});
function collapserow(index) {
ExpandRow = $("#ExpandRow").val();
if (ExpandRow != ‘‘ && ExpandRow != index) {
$(‘#tt‘).datagrid("collapseRow", ExpandRow);
}
if (ExpandRow == index) {
$(‘#tt‘).datagrid("expandRow", index);
}
$("#ExpandRow").val(index);
}
function callback(gridbody) { //拿到子级对象
if (gridbody != null) {
childbody = gridbody;
}
}
function getsub(index, row, callback) {
ddv = $(‘#tt‘).datagrid(‘getRowDetail‘, index).find(‘table.ddv‘);
var tt = $(‘#tt‘);
var cc = row.SE_ID;
ddv.datagrid({
url: ‘../ashx/SellerManager.ashx?type=GetSellerList&se_property=1&se_parentid=‘ + cc,
nowrap: false,
striped: true,
remoteSort: false,
singleSelect: true,
fitColumns: true,
singleSelect: true,
rownumbers: true,
loadMsg: ‘加载中...‘,
height: ‘auto‘,
onClickRow: function (rowIndex, rowData) {
$(‘#tt‘).datagrid(‘unselectAll‘);
ddv.datagrid(‘unselectAll‘);
$(this).datagrid(‘selectRow‘, rowIndex);
},
columns: [[
{ field: ‘SE_NAME‘, title: ‘商家名称‘, formatter: function (value, row, index) {
return "<a href=‘http://seller.jukelai.cn/AStation/?suname=" + row.USERNAME + "&supwd=" + row.UPASSWORD + "‘ target=‘_blank‘>" + row.SE_NAME + "</a>";
}
},
{ field: ‘USERNAME‘, title: ‘用户名‘ },
{ field: ‘SE_TYPE‘, title: ‘商家类型‘ },
{ field: ‘PROVINCES‘, title: ‘所在地‘, formatter: function (value, row, index) {
return row.PROVINCES + ‘-‘ + row.CITY + "-" + row.COUNTY;
}
},
{ field: ‘SE_CONTACT‘, title: ‘联系人‘ },
{ field: ‘SE_PHONE‘, title: ‘联系电话‘ },
{ field: ‘SE_EQUIPMENTCOUNT‘, title: ‘设备数量‘ },
{ field: ‘SE_URL‘, title: ‘网址‘ },
{ field: ‘SE_BUSINESSAREA‘, title: ‘营业面积‘ },
{ field: ‘SE_PROPERTY‘, title: ‘性质‘, formatter: function (value, row, index) {
if (row.SE_PROPERTY == 0) {
return ‘总店‘;
}
else {
return ‘分店‘;
}
}
}
]],
onResize: function () {
$(‘#tt‘).datagrid(‘fixDetailRowHeight‘, index);
},
onLoadSuccess: function (data) {
setTimeout(function () {
$(‘#tt‘).datagrid(‘fixDetailRowHeight‘, index);
}, 0);
if (data.total == 0) {
//console.info(‘进入无数据‘);
var body = $(this).data().datagrid.dc.body2;
//console.info("body:%f", body);
body.find(‘table tbody‘).append(‘<tr><td width="‘ + body.width() + ‘" style="height: 25px; text-align: center; color:Red">抱歉,没有查询到数据</td></tr>‘);
}
}
});
callback(ddv);
}
需注意的地方:
1,子层是异步加载的,在子层加载的时候,第一次点击展开一个表的时候会把下面的内容挤下去,第二次点开的时候就好了。如图:
解决办法:在异步加载的onLoadSuccess里加 上下面几行代码就可以了,如果不写settimeout,直接写函数里面的那一行代码却不行,到最后也没搞明白为什么要这样写,如果有谁懂的,请赐教。
setTimeout(function () {
$(‘#tt‘).datagrid(‘fixDetailRowHeight‘, index);
}, 0);
2,需求是不管是父层还是子层,每次只能选中一条信息,但是实际操作中发现父层和子层可以同时选中,这样的话对数据的操作(编辑、删除)就容易混淆,因为同时选中很多条,你就不知道当你点了删除按钮它会删除哪一条。
解决办法:在两层表格中都加上一个点击行事件(onClickRow),在点击父层的时候让子层的状态改为‘unselectAll’,即取消选择所有行。如图:
3,在2的基础上发现另外一个问题,在父层点击行的时候会报错,提示对象为null,但是alert时却是object,研究了很长时间都找不到答案,最后请教了我的老师,他的一句话让我茅塞顿开。他说:要在回调函数里去拿第二层,也就是要异步的回来之后再调用一个函数去拿,否则代码立即执行,异步的还没有回来当然是空了,alert是停顿的,所以不是null 。
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/study-net/p/4016070.html