Skip to content

Commit 302272b

Browse files
committed
coding
1 parent 0103062 commit 302272b

File tree

2 files changed

+45
-50
lines changed

2 files changed

+45
-50
lines changed

YanZhiwei.JavaScript.Utilities/jquery/datatables/1.10.2/dataTables_example6.aspx

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,64 +19,54 @@
1919
<script type="text/javascript">
2020
var data = [
2121
{
22-
"name": "rfswitch1",
22+
"name": "1",
2323
"ip": "192.168.1.1",
2424
"group": "A"
2525
},
2626
{
27-
"name": "rfswitch2",
28-
"ip": "192.168.1.1",
27+
"name": "2",
28+
"ip": "192.168.1.2",
2929
"group": "B"
3030
},
3131
{
32-
"name": "rfswitch3",
33-
"ip": "192.168.1.2",
34-
"group": "C"
35-
},
36-
{
37-
"name": "rfswitch4",
32+
"name": "3",
3833
"ip": "192.168.1.3",
39-
"group": "D"
34+
"group": "C"
4035
},
4136
{
42-
"name": "rfswitch5",
37+
"name": "4",
4338
"ip": "192.168.1.4",
44-
"group": "A"
39+
"group": "D"
4540
},
4641
{
47-
"name": "rfswitch6",
42+
"name": "5",
4843
"ip": "192.168.1.5",
49-
"group": "B"
44+
"group": "A"
5045
},
5146
{
52-
"name": "rfswitch7",
47+
"name": "6",
5348
"ip": "192.168.1.6",
54-
"group": "C"
49+
"group": "B"
5550
},
5651
{
57-
"name": "rfswitch8",
52+
"name": "7",
5853
"ip": "192.168.1.7",
59-
"group": "D"
54+
"group": "C"
6055
},
6156
{
62-
"name": "rfswitch9",
57+
"name": "8",
6358
"ip": "192.168.1.8",
64-
"group": "A"
59+
"group": "D"
6560
},
6661
{
67-
"name": "rfswitch10",
62+
"name": "9",
6863
"ip": "192.168.1.9",
69-
"group": "B"
64+
"group": "A"
7065
},
7166
{
72-
"name": "rfswitch11",
67+
"name": "10",
7368
"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"
8070
}
8171
];
8272
$(document).ready(function () {
@@ -90,7 +80,6 @@
9080
{
9181
"title": "编辑",
9282
"mData": null,
93-
"bSortable": false,
9483
"width": "25%",
9584
"mRender": function (data, type, row) {
9685
//var context =
@@ -102,53 +91,60 @@
10291
// };
10392
//var html = template(context);//匹配内容
10493
//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>";
10796
return html;
10897
}
10998
}
11099
];
111100
112-
$('#tableLog').executeQuery(_columns);
101+
$('#tableLog').executeQuery(_columns, [[1, "desc"]], 10);
113102
$('#tableLog').addJson(data);
114103
});
115104
116-
function edit(name, ip, group) {
105+
function edit(jsonItem) {
117106
//console.log(name);
118107
editFlag = true;
119108
$("#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);
123112
//应该获得数据也就是要进行更新处理
124113
$("#myModal").modal("show");
125114
}
126115
function del(name, ip, group) {
127116
//这个地方也好弄,可以获取数据
128-
alert(name + ip + group);
117+
$('#tableLog').dataTable().deleteRowByParam('ip', ip);
129118
}
130119
131120
function save() {
132121
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();
140123
var addJson = {
141-
"name": $("#name").val(),
124+
"name": _name,
142125
"ip": $("#ip").val(),
143-
"group": $("#group").val(),
126+
"group": $("#group").val() + "abb",
144127
};
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+
145137
return;
146138
}
147139
</script>
148140
</head>
149141
<body>
150142
<div class="container">
151143
<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>
152148
</div>
153149
<!-- Modal -->
154150
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
@@ -170,11 +166,10 @@
170166
<div class="form-group">
171167
<input type="text" class="form-control" id="group" placeholder="please input rfswitch group" />
172168
</div>
173-
174169
</div>
175170
<div class="modal-footer">
176171
<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>
178173
</div>
179174
</div>
180175
</div>

YanZhiwei.JavaScript.Utilities/jquery/datatables/1.10.2/datatablesUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
/// </summary>
242242
/// <param name="rowIndex">行索引</param>
243243
/// <param name="rowData">新的行数据</param>
244-
$(this).DataTable().row(rowIndex).data(rowData).draw();
244+
$(this).DataTable().row(rowIndex).invalidate().data(rowData).draw(false);
245245
},
246246
deleteRowByIndex: function (rowIndex) {
247247
/// <summary>

0 commit comments

Comments
 (0)