-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
122 lines (109 loc) · 3.74 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Kendo UI DataSource CRUD Example</title>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.318/styles/kendo.common.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.318/styles/kendo.bootstrap.min.css" />
</head>
<body style="margin:100px">
<div class="panel panel-default">
<div class="panel-body">
<label for="name">Enter users name click add:</label>
<div class="input-group">
<input type="text" id="name" class="form-control" placeholder="name">
<span class="input-group-btn">
<button class="btn btn-primary" id="add" type="button">Add</button>
</span>
</div>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.318/js/kendo.all.min.js"></script>
<script type="text/x-kendo-template" id="template">
<tr>
<td>#:id#</td>
<td>
<input value="#:name#">
<button type="button" data-id="#:id#" id="update" class="btn btn-default btn-xs">update</button>
<button type="button" data-id="#:id#" id="delete" class="btn btn-danger btn-xs">delete</button>
</td>
</tr>
</script>
<script>
//create DataSource instance
var dataSource = new kendo.data.DataSource({
autoSync: true, //sync changes with restful API automatically
transport: {
read: {
url: 'http://localhost:3000/users',
dataType: 'json', //not needed jQuery figures it out, shown to be verbose
type: 'GET' //defined but, this is the default
},
create: {
url: 'http://localhost:3000/users',
type: 'POST'
},
update: {
url: function(data) {
return 'http://localhost:3000/users/' + data.id;
},
type: 'PUT'
},
destroy: {
url: function(data) {
return 'http://localhost:3000/users/' + data.id;
},
type: 'DELETE'
}
},
schema: {
model: {
id: 'id'
}
},
change: function() {
$('tbody').html(
kendo.render(
kendo.template(
$('#template').html()
), this.view()
)
);
}
});
dataSource.read();
$('#add').on('click', function() {
dataSource.add({
name: $('#name').val()
});
//dataSource.sync(); //using autoSync: true so don't have to call
});
$('tbody').on('click', '#delete', function() {
var $this = $(this);
dataSource.remove(
dataSource.get($this.data('id'))
);
//dataSource.sync(); //using autoSync: true so don't have to call
});
$('tbody').on('click', '#update', function() {
var $this = $(this);
dataSource.get(
$this.data('id')
).set('name', $this.prev('input').val());
//dataSource.sync(); //using autoSync: true so don't have to call
});
</script>
</body>
</html>