Skip to content

Commit 7f46311

Browse files
committed
增加getRowHtmlByParam函数以及示例。
1 parent 0515700 commit 7f46311

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

YanZhiwei.JavaScript.Utilities/jquery/datatables/1.10.2/datatables.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
var table = $('#tableLog').dataTable();
104104
var _row = table.getRowByParam('time', '2015-10-11');
105105
_row.data().time = '2015-10-22';
106-
$('#tableLog').DataTable().draw();
107106
}
108107
function deleteRowByParam() {
109108
var table = $('#tableLog').dataTable();
@@ -113,10 +112,14 @@
113112
var table = $('#tableLog').dataTable();
114113
var _rowIndex = table.getRowIndexByParam('time', '2015-10-13');
115114
if (_rowIndex >= 0) {
116-
// var _row = $('#tableLog').DataTable().row(_rowIndex);
117115
table.updateRowByIndex(_rowIndex, { "time": "2015-10-22", "log": "test", "status": "不正常" });
118116
}
119117
}
118+
function getRowHtmlByParam() {
119+
var table = $('#tableLog').dataTable();
120+
var _row = table.getRowHtmlByParam('time', '2015-10-11');
121+
$(_row).css("background-color", "red");
122+
}
120123
</script>
121124
</head>
122125
<body>
@@ -136,5 +139,6 @@
136139
<input type="button" value="getRowByParam" onclick="getRowByParam()" />
137140
<input type="button" value="getRowIndexByParam" onclick="getRowIndexByParam()" />
138141
<input type="button" value="deleteRowByParam" onclick="deleteRowByParam()" />
142+
<input type="button" value="getRowHtmlByParam" onclick="getRowHtmlByParam()" />
139143
</body>
140144
</html>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,25 @@
442442
});
443443
return _rows;
444444
},
445+
getRowHtmlByParam: function (key, value) {
446+
/// <summary>
447+
/// 根据键值搜索nRow
448+
/// </summary>
449+
/// <param name="key" type="type">需要精确匹配的属性名称</param>
450+
/// <param name="value" type="type">需要精确匹配的属性值,可以是任何类型,只要保证与 key 指定的属性值保持一致即可</param>
451+
/// <returns type="">nRow</returns>
452+
var _id = $(this).attr('id'),
453+
_table = $('#' + _id).dataTable(),
454+
_row = null;
455+
var _nTrs = _table.fnGetNodes();//fnGetNodes获取表格所有行
456+
for (var i = 0; i < _nTrs.length; i++) {
457+
var _rowData = _table.fnGetData(_nTrs[i]);
458+
if (_rowData[key] == value) {
459+
_row = _nTrs[i];
460+
}
461+
}
462+
return _row;
463+
},
445464
deleteRowByParam: function (key, value) {
446465
/// <summary>
447466
/// 根据键值删除行数据

0 commit comments

Comments
 (0)