|
19 | 19 | <script type="text/javascript"> |
20 | 20 | var data = [ |
21 | 21 | { |
22 | | - "name": "rfswitch1", |
| 22 | + "name": "1", |
23 | 23 | "ip": "192.168.1.1", |
24 | 24 | "group": "A" |
25 | 25 | }, |
26 | 26 | { |
27 | | - "name": "rfswitch2", |
28 | | - "ip": "192.168.1.1", |
| 27 | + "name": "2", |
| 28 | + "ip": "192.168.1.2", |
29 | 29 | "group": "B" |
30 | 30 | }, |
31 | 31 | { |
32 | | - "name": "rfswitch3", |
33 | | - "ip": "192.168.1.2", |
34 | | - "group": "C" |
35 | | - }, |
36 | | - { |
37 | | - "name": "rfswitch4", |
| 32 | + "name": "3", |
38 | 33 | "ip": "192.168.1.3", |
39 | | - "group": "D" |
| 34 | + "group": "C" |
40 | 35 | }, |
41 | 36 | { |
42 | | - "name": "rfswitch5", |
| 37 | + "name": "4", |
43 | 38 | "ip": "192.168.1.4", |
44 | | - "group": "A" |
| 39 | + "group": "D" |
45 | 40 | }, |
46 | 41 | { |
47 | | - "name": "rfswitch6", |
| 42 | + "name": "5", |
48 | 43 | "ip": "192.168.1.5", |
49 | | - "group": "B" |
| 44 | + "group": "A" |
50 | 45 | }, |
51 | 46 | { |
52 | | - "name": "rfswitch7", |
| 47 | + "name": "6", |
53 | 48 | "ip": "192.168.1.6", |
54 | | - "group": "C" |
| 49 | + "group": "B" |
55 | 50 | }, |
56 | 51 | { |
57 | | - "name": "rfswitch8", |
| 52 | + "name": "7", |
58 | 53 | "ip": "192.168.1.7", |
59 | | - "group": "D" |
| 54 | + "group": "C" |
60 | 55 | }, |
61 | 56 | { |
62 | | - "name": "rfswitch9", |
| 57 | + "name": "8", |
63 | 58 | "ip": "192.168.1.8", |
64 | | - "group": "A" |
| 59 | + "group": "D" |
65 | 60 | }, |
66 | 61 | { |
67 | | - "name": "rfswitch10", |
| 62 | + "name": "9", |
68 | 63 | "ip": "192.168.1.9", |
69 | | - "group": "B" |
| 64 | + "group": "A" |
70 | 65 | }, |
71 | 66 | { |
72 | | - "name": "rfswitch11", |
| 67 | + "name": "10", |
73 | 68 | "ip": "192.168.1.10", |
74 | | - "group": "C" |
75 | | - }, |
76 | | - { |
77 | | - "name": "rfswitch12", |
78 | | - "ip": "192.168.1.11", |
79 | | - "group": "D" |
| 69 | + "group": "B" |
80 | 70 | } |
81 | 71 | ]; |
82 | 72 | $(document).ready(function () { |
|
90 | 80 | { |
91 | 81 | "title": "编辑", |
92 | 82 | "mData": null, |
93 | | - "bSortable": false, |
94 | 83 | "width": "25%", |
95 | 84 | "mRender": function (data, type, row) { |
96 | 85 | //var context = |
|
102 | 91 | // }; |
103 | 92 | //var html = template(context);//匹配内容 |
104 | 93 | //return html; |
105 | | - var html = "<button type='button' class='btn btn-primary btn-sm' onclick=edit('" + row.name + "','" + row.ip + "','" + row.group + "')> 编辑 </button>\n" + |
106 | | - "<button type='button' class='btn btn-danger btn-sm' onclick='del('" + row.name + "','" + row.ip + "','" + row.group + "')>删除</button>"; |
| 94 | + var html = "<button type='button' class='btn btn-primary btn-sm' onclick=edit(" + JSON.stringify(row) + ")> 编辑 </button>\n" + |
| 95 | + "<button type='button' class='btn btn-danger btn-sm' onclick=del('" + row.name + "','" + row.ip + "','" + row.group + "')>删除</button>"; |
107 | 96 | return html; |
108 | 97 | } |
109 | 98 | } |
110 | 99 | ]; |
111 | 100 |
|
112 | | - $('#tableLog').executeQuery(_columns); |
| 101 | + $('#tableLog').executeQuery(_columns, [[1, "desc"]], 10); |
113 | 102 | $('#tableLog').addJson(data); |
114 | 103 | }); |
115 | 104 |
|
116 | | - function edit(name, ip, group) { |
| 105 | + function edit(jsonItem) { |
117 | 106 | //console.log(name); |
118 | 107 | editFlag = true; |
119 | 108 | $("#myModalLabel").text("Edit"); |
120 | | - $("#name").val(name);//为什么也有作用 |
121 | | - $("#ip").val(ip).attr("disabled", true); |
122 | | - $("#group").val(group); |
| 109 | + $("#name").val(jsonItem.name);//为什么也有作用 |
| 110 | + $("#ip").val(jsonItem.ip).attr("disabled", true); |
| 111 | + $("#group").val(jsonItem.group); |
123 | 112 | //应该获得数据也就是要进行更新处理 |
124 | 113 | $("#myModal").modal("show"); |
125 | 114 | } |
126 | 115 | function del(name, ip, group) { |
127 | 116 | //这个地方也好弄,可以获取数据 |
128 | | - alert(name + ip + group); |
| 117 | + $('#tableLog').dataTable().deleteRowByParam('ip', ip); |
129 | 118 | } |
130 | 119 |
|
131 | 120 | function save() { |
132 | 121 | var flag = $("#myModalLabel").text(); |
133 | | - //var flag = Edit; |
134 | | - if (flag == "Edit") { |
135 | | - //get input and ajax |
136 | | - alert("Edit"); |
137 | | - return; |
138 | | - } |
139 | | - alert("add");//get input and ajax |
| 122 | + var _name = $("#name").val(); |
140 | 123 | var addJson = { |
141 | | - "name": $("#name").val(), |
| 124 | + "name": _name, |
142 | 125 | "ip": $("#ip").val(), |
143 | | - "group": $("#group").val(), |
| 126 | + "group": $("#group").val() + "abb", |
144 | 127 | }; |
| 128 | + if (flag == "Edit") { |
| 129 | + var _table = $('#tableLog').dataTable(); |
| 130 | + var _rowIndex = _table.getRowIndexByParam('ip', $("#ip").val()); |
| 131 | + _table.deleteRowByParam('ip', $("#ip").val()); |
| 132 | + _table.addJson(addJson); |
| 133 | + $('#myModal').modal('hide'); |
| 134 | + console.log("_rowIndex:" + _rowIndex); |
| 135 | + } |
| 136 | +
|
145 | 137 | return; |
146 | 138 | } |
147 | 139 | </script> |
148 | 140 | </head> |
149 | 141 | <body> |
150 | 142 | <div class="container"> |
151 | 143 | <table id="tableLog" class="table table-striped table-bordered"></table> |
| 144 | + <div class="row"> |
| 145 | + |
| 146 | + <button type="button" class="btn blue" id="btnAddItem">增加 </button> |
| 147 | + </div> |
152 | 148 | </div> |
153 | 149 | <!-- Modal --> |
154 | 150 | <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> |
|
170 | 166 | <div class="form-group"> |
171 | 167 | <input type="text" class="form-control" id="group" placeholder="please input rfswitch group" /> |
172 | 168 | </div> |
173 | | - |
174 | 169 | </div> |
175 | 170 | <div class="modal-footer"> |
176 | 171 | <button type="button" class="btn btn-default" data-dismiss="modal">close</button> |
177 | | - <button type="button" class="btn btn-primary" id="save">save</button> |
| 172 | + <button type="button" class="btn btn-primary" id="save" onclick="save()">save</button> |
178 | 173 | </div> |
179 | 174 | </div> |
180 | 175 | </div> |
|
0 commit comments