easyui全选、取消所有页

摘要:easyui全选、取消所有页

关键代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<script type="text/javascript">
var type='select' //模式:选中/取消
var selected=new Array(); //已选中的行
var canceled=new Array(); //已取消的行
$(function(){
$('#datalist').datagrid({
view: myview,
//fitColumns: true,
algin:'center',
url:'<%=request.getContextPath()%>/sys/log/ajaxDatagrid',
idField:'LOG_ID',
columns:[[
{field:'LOG_ID',title:'ID',width:'40',checkbox:true},
{field:'NUM',title:'序号',width:'40'},
{field:'USER_NAME',title:'用户',width:'80',align:'center'},
{field:'SYSTEM',title:'平台',width:'60',align:'center',formatter:dataFormat},
{field:'FUNC_RIGHT_NAME',title:'功能',width:'200',align:'center'},
{field:'MOD_TIME',title:'时间',width:'150',align:'center'},
{field:'UUID',title:'UUID',width:'275',align:'center'},
{field:'DETAIL',title:'具体内容',align:'left',width:'400',formatter:function(value,row,index){
var html='<a href="javascript:view('+row.LOG_ID+')">'+value+'</a>';
return html;
}
}
]],
height:620,
pageSize:12,
pageList:[12,24,36],
pagination:true
})

$('#datalist').datagrid({onLoadSuccess :function(data){
initRows()//翻页初始化
}})
$('#datalist').datagrid({onCheckAll :function(){
type='cancel'//切换为取消模式
selected=new Array();
canceled=new Array();
}})
$('#datalist').datagrid({onUncheckAll :function(){
type='select'//切换为选中模式
selected=new Array();
canceled=new Array();
}})
$('#datalist').datagrid({onSelect:function(index,row){
//选中某条数据时:若是select模式则在selected变量中添加一个id(若已存在则不添加),
//若是cancel模式,则从canceled变量中删除该id
if(type=='select'){
if(selected.indexOf(row.LOG_ID)==-1){
selected.push(row.LOG_ID)
}
}else{
var index = canceled.indexOf(row.LOG_ID)
if(index!=-1){
canceled.splice(index,1)
}
}
}})
$('#datalist').datagrid({onUnselect:function(index,row){
//取消某条数据时:若是select模式则从selected变量中删除该id,
//若是cancel模式,则在canceled变量中添加一个id(若已存在则不添加)
if(type=='select'){
var index = selected.indexOf(row.LOG_ID)
if(index!=-1){
selected.splice(index,1)
}
}else{
if(canceled.indexOf(row.LOG_ID)==-1){
canceled.push(row.LOG_ID)
}
}
}})


})
//翻页初始化
function initRows(){
var l = $('#datalist').datagrid('getRows').length
if(type=='select'){
//若是select模式,则先将该页所有行取消选中,在选中selected中本页的行
var myselected=new Array();
for (var i=0;i<selected.length;i++){
var index=$('#datalist').datagrid('getRowIndex',selected[i])
if(index!=-1){
myselected.push(index)
}
}
for (var i=0;i<l;i++){
$('#datalist').datagrid('unselectRow',i)
}
for (var i=0;i<l;i++){
if(myselected.indexOf(i)!=-1){
$('#datalist').datagrid('selectRow',i)
}
}
}else{
//若是cancel模式,则先将该页所有行选中,再取消选中canceled中本页的行
var mycanceled=new Array();
for (var i=0;i<canceled.length;i++){
var index=$('#datalist').datagrid('getRowIndex',canceled[i])
if(index!=-1){
mycanceled.push(index)
}
}
for (var i=0;i<l;i++){
$('#datalist').datagrid('selectRow',i)
}
for (var i=0;i<l;i++){
if(mycanceled.indexOf(i)!=-1){
$('#datalist').datagrid('unselectRow',i)
}
}
}

}

function chmod(){
if(type=='select'){
alert('selected:'+selected)
}else{
alert('canceled:'+canceled)
}

}

</script>
<div class="layer">
<div class="search_form" style="margin-bottom:20px;">
<form>
<table width="85%">
<input type="button" value="变更授权" onclick="chmod()"/>
</table>
</form>
</div>

<div class="common_list">
<table class="tablelist comm" id="datalist" ></table>
</div>
</div>

全部代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<style>
.sipt{width:100px!important}
#param3[class="sipt"]{width:230px!important}
#param7[class="sipt"]{width:230px!important}
</style>
<script type="text/javascript">
var type='select' //模式:选中/取消
var selected=new Array(); //已选中的行
var canceled=new Array(); //已取消的行
$(function(){
judgement(1);
judgement(5);
$('#datalist').datagrid({
view: myview,
//fitColumns: true,
algin:'center',
url:'<%=request.getContextPath()%>/sys/log/ajaxDatagrid',
idField:'LOG_ID',
columns:[[
{field:'LOG_ID',title:'ID',width:'40',checkbox:true},
{field:'NUM',title:'序号',width:'40'},
{field:'USER_NAME',title:'用户',width:'80',align:'center'},
{field:'SYSTEM',title:'平台',width:'60',align:'center',formatter:dataFormat},
{field:'FUNC_RIGHT_NAME',title:'功能',width:'200',align:'center'},
{field:'MOD_TIME',title:'时间',width:'150',align:'center'},
{field:'UUID',title:'UUID',width:'275',align:'center'},
{field:'DETAIL',title:'具体内容',align:'left',width:'400',formatter:function(value,row,index){
var html='<a href="javascript:view('+row.LOG_ID+')">'+value+'</a>';
return html;
}
}
]],
height:620,
pageSize:12,
pageList:[12,24,36],
pagination:true
})



$('#datalist').datagrid({onLoadSuccess :function(data){
initRows()//翻页初始化
}})
$('#datalist').datagrid({onCheckAll :function(){
type='cancel'//切换为取消模式
selected=new Array();
canceled=new Array();
}})
$('#datalist').datagrid({onUncheckAll :function(){
type='select'//切换为选中模式
selected=new Array();
canceled=new Array();
}})
$('#datalist').datagrid({onSelect:function(index,row){
//选中某条数据时:若是select模式则在selected变量中添加一个id(若已存在则不添加),若是cancel模式,则从canceled变量中删除该id
if(type=='select'){
if(selected.indexOf(row.LOG_ID)==-1){
selected.push(row.LOG_ID)
}
}else{
var index = canceled.indexOf(row.LOG_ID)
if(index!=-1){
canceled.splice(index,1)
}
}
}})
$('#datalist').datagrid({onUnselect:function(index,row){
//取消某条数据时:若是select模式则从selected变量中删除该id,若是cancel模式,则在canceled变量中添加一个id(若已存在则不添加)
if(type=='select'){
var index = selected.indexOf(row.LOG_ID)
if(index!=-1){
selected.splice(index,1)
}
}else{
if(canceled.indexOf(row.LOG_ID)==-1){
canceled.push(row.LOG_ID)
}
}
}})


})
//翻页初始化
function initRows(){
var l = $('#datalist').datagrid('getRows').length
if(type=='select'){
//若是select模式,则先将该页所有行取消选中,在选中selected中本页的行
var myselected=new Array();
for (var i=0;i<selected.length;i++){
var index=$('#datalist').datagrid('getRowIndex',selected[i])
if(index!=-1){
myselected.push(index)
}
}
for (var i=0;i<l;i++){
$('#datalist').datagrid('unselectRow',i)
}
for (var i=0;i<l;i++){
if(myselected.indexOf(i)!=-1){
$('#datalist').datagrid('selectRow',i)
}
}
}else{
//若是cancel模式,则先将该页所有行选中,再取消选中canceled中本页的行
var mycanceled=new Array();
for (var i=0;i<canceled.length;i++){
var index=$('#datalist').datagrid('getRowIndex',canceled[i])
if(index!=-1){
mycanceled.push(index)
}
}
for (var i=0;i<l;i++){
$('#datalist').datagrid('selectRow',i)
}
for (var i=0;i<l;i++){
if(mycanceled.indexOf(i)!=-1){
$('#datalist').datagrid('unselectRow',i)
}
}
}

}

function chmod(){
if(type=='select'){
alert('selected:'+selected)
}else{
alert('canceled:'+canceled)
}

}
function dataFormat(value,row,index){
if(value=='0'){
return 'web端';
}else if(value=='1'){
return '移动端';
}
}
function query(){
var param='';
if($('#param3').val()!=''){
param+=$('#param1').val()+',';
param+=$('#param2').val()+',';
param+=$('#param3').val()+',';
}
if($('#param3').val()!=''&&$('#param7').val()!=''){
param+=$('#param4').val()+',';
}
if($('#param7').val()!=''){
param+=$('#param5').val()+',';
param+=$('#param6').val()+',';
param+=$('#param7').val()+',';
}
if(param!=''){
param=param.substring(0, param.length-1);
}
$('#datalist').datagrid('load',{param:param})
}
/**
* 根据param1(param5)的选择,改变param2(param6)、param3(param7)的内容及类型
*/
function judgement(num){
$('#param'+(num+1)).empty();
var obj = $('#param'+(num+2)).parent()
obj.empty()
var p = $('#param'+num).val();
if(p=='3'){
obj.append('<input class="ssl" type="text" id="param'+(num+2)+'" />')
if(num==1){
$('#param'+(num+1)).append('<option value=">">大于</option><option value="=">等于</option><option value="<">小于</option>')
$('#param'+(num+2)).click(function(){WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss'})})
}else{
$('#param'+(num+1)).append('<option value="<">小于</option><option value="=">等于</option><option value=">">大于</option>')
$('#param'+(num+2)).click(function(){WdatePicker({startDate:'%y-%M-%d 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss'})})
}
}else if(p=='8'){
$('#param'+(num+1)).append('<option value="like">包含</option>')
obj.append('<input class="ssl" type="text" id="param'+(num+2)+'"/>')
}else if(p=='1'||p=='4'){
$('#param'+(num+1)).append('<option value="=">等于</option>')
if(p=='1'){
obj.append('<select class="sipt" id="param'+(num+2)+'"><option value="0">web端</option><option value="1">移动端</option></select>')
}else{
obj.append('<select class="sipt" id="param'+(num+2)+'"><option value="0">使用日志</option>'
+'<option value="1">正常操作日志</option><option value="2">错误日志</option></select>')
}
}else{
$('#param'+(num+1)).append('<option value="like">包含</option><option value="=">等于</option>')
obj.append('<input class="ssl" type="text" id="param'+(num+2)+'"/>')
}
}

function view(logId){
layer.open({
type:2,
content:'<%=request.getContextPath()%>/sys/log/view?logId='+logId,
area:['600px','500px'],
closeBtn :0,
title:['查看']
})
}

</script>


<div class="nav">
<div class="current">系统管理>>日志管理</div>
<div class="btns">
</div>
</div>

<div class="layer">
<div class="search_form" style="margin-bottom:20px;">
<form>
<table width="85%">
<tr>
<td><select id="param1" onchange="judgement(1)" class="sipt">
<option value="0">用户</option>
<option value="1">平台</option>
<option value="2">功能</option>
<option value="3">时间</option>
<option value="4">日志类型</option>
<option value="5">终端号</option>
<option value="6">应用名称</option>
<option value="7">UUID</option>
<option value="8">具体内容</option>
</select></td>
<td>
<select id="param2" class="sipt"></select></td>
<td><input type="text" id="param3" class="ssl"/></td>
<td>
<select id="param4" class="sipt">
<option value="and">并且</option>
<option value="or">或者</option>
</select></td>
<td>
<select id="param5" onchange="judgement(5)" class="sipt">
<option value="0">用户</option>
<option value="1">平台</option>
<option value="2">功能</option>
<option value="3">时间</option>
<option value="4">日志类型</option>
<option value="5">终端号</option>
<option value="6">应用名称</option>
<option value="7">UUID</option>
<option value="8">具体内容</option>
</select></td>
<td>
<select id="param6" class="sipt"></select></td>
<td><input type="text" id="param7" class="ssl"/></td>
<td><img src="<%=request.getContextPath()%>/resources/images/btn-search.png" onclick="query()" style="height:35px;cursor: pointer;"/>
<input type="button" value="变更授权" onclick="chmod()"/></td>
</tr>
</table>
</form>
</div>

<div class="common_list">
<table class="tablelist comm" id="datalist" ></table>
</div>
</div>
</body>
</html>