-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery-jsgrid-crud.html
More file actions
200 lines (179 loc) · 6.54 KB
/
jquery-jsgrid-crud.html
File metadata and controls
200 lines (179 loc) · 6.54 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link href="/js/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="/js/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css" />
<!-- <link href="/js/jqGrid/css/ui.jqgrid.css" rel="stylesheet" type="text/css" /> -->
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.2/jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.2/jsgrid-theme.min.css" />
</head>
<body>
<div class="container">
<h1>jsGrid 예제</h1>
<div id="jsGrid"></div>
</div>
<script src="/js/jquery/dist/jquery.min.js"></script>
<script src="/js/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="js/handlebars/handlebars.min.js"></script>
<!-- <script src="/js/jqGrid/js/minified/jquery.jqGrid.min.js"></script> -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.2/jsgrid.min.js"></script>
<script type="text/javascript">
var myRend = function (value, item) {
var result = "<td>";
var arrs = value.split(',');
for (var i in arrs) {
var item = arrs[i];
result = result + item + "<br>";
}
result = result + "</td>";
return result;
}
$(document).ready(function () {
var teamName = "";
var id = -10;
$("#excutors").val('');
$("#excutors").prop('disabled', true);
$("#saveBtn").prop('disabled', true);
$("#saveBtn").click(function () {
if (id == -10) {
alert("팀을 선택해주세요.");
}
else {
var text = $('#excutors').val();
var param = {
excutors: text,
team2: teamName,
id: id
};
$.ajax({
type: "POST",
url: "save_excutors",
data: param,
success: function (data) {
alert("저장되었습니다.");
}
});
}
});
var excutors = [{
"excutor": ""
}];
function drawInputJsGrid(campusList, departmentList) {
$("#jsGrid").jsGrid({
width: "100%",
height: "400px",
autoload: true,
inserting: true,
editing: true,
sorting: true,
paging: true,
selecting: true,
pageSize: 15,
pageButtonCount: 5,
rowClick: function (args) {
$("#excutors").prop('disabled', false);
$("#saveBtn").prop('disabled', false);
teamName = args.item.team2;
id = args.item.id;
var campusName = '';
for (var i in campusList) {
if (campusList[i].id == args.item.campus) {
campusName = campusList[i].name;
}
}
var deptName = '';
for (var i in departmentList) {
if (departmentList[i].id == args.item.department) {
deptName = departmentList[i].name;
}
}
$("#excutor").text("실행위원 (" + campusName + "-" + deptName + "-" + args.item.team1 + "-" + args.item.team2 + ")")
$("#status").html("복수의 인원을 입력할 때는 사람마다 쉼표(,)로 구분해주세요 <br>이름 뒤에 생년월일을 입력하실 수 있습니다. YYYYMMDD 예)홍길동19701130");
if (id != null) {
$.ajax({
url: "excutors/" + id,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
type: 'GET',
success: function (data) {
var content = "";
for (var i in data) {
content = content + data[i].name + ",";
}
$('#excutors').height(((data.length / 25) + 1) * 30);
$('#excutors').val(content);
},
error: function (jqXHR, textStatus, error) {
alert("error" + JSON.stringify(textStatus) + " " + JSON.stringify(error));
}
});
}
else {
$('#excutors').val("");
}
},
controller: {
loadData: function (filter) {
return $.ajax({
type: "GET",
url: "items.json",
})
},
insertItem: function (item) {
return $.ajax({
type: "POST",
url: "insert_item",
data: item
});
},
updateItem: function (item) {
return $.ajax({
type: "POST",
url: "update_item",
data: item
});
},
deleteItem: function (item) {
return $.ajax({
type: "POST",
url: "delete_item",
data: item
});
},
},
confirmDeleting: true,
deleteConfirm: "삭제하시겠습니까?",
fields: [
{
align: "center", width: "auto", name: "campus", title: "캠퍼스", type: "select",
items: campusList, valueField: "id", textField: "name", validate: "required"
},
{
align: "center", width: "auto", name: "department", title: "본부", type: "select",
items: departmentList, valueField: "id", textField: "name", validate: "required"
},
{ align: "center", width: "auto", name: "team1", title: "본부사역팀", type: "text" },
{ align: "center", width: "auto", name: "team2", title: "사역팀", type: "text" },
{ align: "center", width: "auto", name: "pastor", title: "교역자", type: "text", cellRenderer: myRend },
{ align: "center", width: "auto", name: "elder", title: "장로", type: "text", cellRenderer: myRend },
{ align: "center", width: "auto", name: "cheif", title: "팀장", type: "text", cellRenderer: myRend },
{ align: "center", width: "auto", name: "manager", title: "총무", type: "text", cellRenderer: myRend },
{ align: "center", width: "auto", type: "control" }
]
});
}
$.ajax({
type: "GET",
url: "./campuslist.json",
success: function (data) {
var campusList = data.campusList;
var departmentList = data.departmentList;
drawInputJsGrid(campusList, departmentList);
}
});
});
</script>
</body>
</html>