bootstrap-table给单元格添加链接

1、html页面

<table id="tb_table"></table>
2、js页面

$("#tb_table").bootstrapTable({
method: 'get', //请求方式
url: '/order/orderList', //请求数据的URL
... //中间的其他选择暂时省略
columns: [{
field: 'oprate',
title: '操作',
100,
align: 'center',
valign: 'middle',
formatter: aFormatter //添加超链接的方法
}]
});
添加aFormatter的方法:

function aFormatter(value, row, index) {
return [
'<a href="#">链接</a>'
].join("")

————————————————
版权声明:本文为CSDN博主「LLL_LH」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/LLL_liuhui/java/article/details/80340307

===========================

继续,

formatter function (value,row,index){} 参数的含义

datagarid的formatter属性
formatter:function(value,row,index){}
formatter 属于列参数,表示对于当前列的数据进行格式化操作,它是一个函数,有三个参数,分别是value,row,index
value:表示当前单元格中的值
row:表示当前行
index:表示当前行的下标
可以使用return返回想要的数据显示在单元格中

例子:

{field:"operate",title:"操作",align:"center",valign:"middle",formatter:function(value,row,index){
     return "<a href='javascript:;' onclick='editRow(event)'>编辑</a>&nbsp;&nbsp;<a href='javascript:;' onclick='deleteRow(event)'>删除</a>";
 }}

  • 1
  • 2
  • 3
  • 4

效果图:
在这里插入图片描述
例二:

{field:‘is_hot’,title:‘是否热门’,20,formatter: function(value,row,index){
if(value==1){
return “是”;
}else{
return “否”;
}

============================
所以其他列的参数, +row.message_number+

function aFormatter(value, row, index) {
return [
'<a href="#'+row.mobile+'">'+value+'</a>'
].join("")
};

原文地址:https://www.cnblogs.com/apolloren/p/13255680.html