gpt4 book ai didi

javascript - 如何在 Datatable 的单元格内显示有关图标单击事件的对话框?

转载 作者:行者123 更新时间:2023-11-30 17:40:09 25 4
gpt4 key购买 nike

在我的数据表自定义指令中,我在一个单元格中有三个操作图标。

$(document).ready(function () {
var oTable = $("#elem").dataTable({
'bJQueryUI': false,
'sScrollY': '300px',
'bScrollInfinite': true,
'bSearchable': true,
'bScrollCollapse': true,
'sDom': 'tSi',
"bDeferRender": true,
'bPaginate': true,
'aaSorting': [
[1, 'asc']
],
'aaData': scope.datasource,
"fnRowCallback": processRow,
"aoColumnDefs": [{
"bSortable": true,
"bSearchable": true,
"sWidth": "20%",
"sTitle": "Name",
"sName": "name",
"aTargets": [0],
"mData": "name",
"mRender": function (data, type, full) {
return '<a href="#/Attachments/' + full.id + '">' + data + ' </a>';
}
}, {
"bSortable": true,
"bSearchable": true,
"sWidth": "18%",
"sTitle": "Types",
"sName": "types",
"aTargets": [1],
"mData": "types"
}, {
"bSortable": true,
"bSearchable": true,
"sWidth": "10%",
"sTitle": "File Type",
"sName": "fileType",
"aTargets": [2],
"mData": "fileType"
}, {
"bSortable": true,
"bSearchable": true,
"sWidth": "18%",
"sTitle": "Modified Time",
"sName": "modifiedTime",
"aTargets": [3],
"mData": "modifiedTime"
}, {
"bSortable": false,
"bSearchable": true,
"sWidth": "25%",
"sTitle": "Action Buttons",
"aTargets": [4],
"mData": "",
"mRender": function () {
return '<div class = "center">
<span>
<i class = "glyphicon-info-sign glyphicon"
id="info" style="color:#32a5e8"
onmouseover="this.style.color=\'crimson\'"
onmouseout="this.style.color=\'#32a5e8\'">
</i>
</span>
<i class = "glyphicon-edit glyphicon" style="color:#32a5e8"
onmouseover="this.style.color=\'crimson\'"
onmouseout="this.style.color=\'#32a5e8\'" ng-click="">
</i>
<span>
<i class = "glyphicon-remove glyphicon" style="color:#32a5e8"
onmouseover="this.style.color=\'crimson\'"
onmouseout="this.style.color=\'#32a5e8\'" ng-click="">
</i>
</span>
</div>';
}
}]
});

$("#elem tbody tr td:eq(4)").on('click', function () {
var data = oTable.fnGetData(this);
console.log("clicked inside table -- data: ", oTable.fnGetData());

var position = oTable.fnGetPosition(this);
console.log("clicked position inside table -- position: ", position);

});
});

点击“信息”图标后,我需要在弹出窗口中显示一条消息。
现在,我尝试使用 fnGetPosition() 方法,该方法为单元格内的所有图标返回相同的位置。如果我能区分它们的位置值,我将很容易在点击“信息”图标时显示对话框。
我现在如何使用它?或者还有其他方法吗?

最佳答案

$(document).ready(function() {
var oTable = $("#elem").dataTable({
'bJQueryUI':false,
'sScrollY': '300px',
'bScrollInfinite':true,
..........
..........
});
$("#elem tbody").delegate("tr i", "click", function (e) {
e.preventDefault();
var self = $(this);
var pos = self.closest('tr').index();// <-- this will give you row index.

if (self.hasClass('glyphicon-edit')) {
// Do something
}else if (self.hasClass('glyphicon-info-sign')){
// Do something
}else if(self.hasClass('glyphicon-remove'){
// Do something
}
});

关于javascript - 如何在 Datatable 的单元格内显示有关图标单击事件的对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21251622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com