gpt4 book ai didi

javascript - 如何将 anchor 标记添加到每行的列 Bootstrap-Datatable

转载 作者:行者123 更新时间:2023-11-28 19:48:59 24 4
gpt4 key购买 nike

我有一个页面,其中的数据通过某些搜索事件刷新。

数据由 Bootstrap-Datatable 通过 ajax 渲染,返回 json 响应

这里是渲染表的小代码:

function renderTable(url, table, query) {
$.ajax({url: url,
data: query,
success: function(data) {
$(table).dataTable({
aaData: data.aaData,
aoColumns: data.aoColumns,
bProcessing: true,
iDisplayLength: 50,
bDestroy: true
});
}
});
}

This is prototype of data by bootstrap datatable

我希望所有 Name 列都应该是一个 anchor 标记,其中包含指向某个带有名称参数和值的 url(显示个人资料)的链接。就像-

http://url.com/profile?name=Airi%20satau

最佳答案

我遇到了同样的情况,我必须在数据表列中显示 anchor 标记来代替原始文本。下面给出了对我有用的解决方案

$(document).ready(function () {
$('#example').DataTable({
"ajax": yourDataURL,
"columns": [ // Defines column for the output table
{ "data": "InventoryId" }, // Attribute of item in collection
{ "data": "InventoryName" },
{ "data": "InventoryManager" },
{ "data": "InventoryActive1",
"orderable": false,
"searchable": false,
"render": function(data,type,row,meta) { // render event defines the markup of the cell text
var a = '<a><i class="fa fa-edit"></i> ' + row.InventoryName +'</a>'; // row object contains the row data
return a;
}
}
]
});
});

希望这对陷入相同情况的人有所帮助

关于javascript - 如何将 anchor 标记添加到每行的列 Bootstrap-Datatable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23825895/

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