本文在上文的基础上,返回的数据中多了一个link超链接跳转的字段,,需要在Handsontable中显示超链接。

  

<!DOCTYPE html>
<html>
<head>
<title>handsontable demo</title>
<meta charset="utf-8">
<link rel="stylesheet" href="handsontable/htstyle.css">
<link rel="stylesheet" href="handsontable/htstyle-custom.css">
<script src="handsontable/jquery-1.12.1.js"></script>
<script src="handsontable/handsontable.full.js"></script>
</head>
<body>
<div id="example"></div> <script>
var data = [
{ riqi: '2017-01', address: '北京', goods: '冰箱', price: '3399', sales: 530, del: '', link: "<a href='http://www.baidu.com' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-01', address: '天津', goods: '空调', price: '4299', sales: 522, del: '', link: "<a href='handsontable_1.htm' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-01', address: '上海', goods: '洗衣机', price: '1299', sales: 544, del: '', link: "<a href='http://www.baidu.com' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-01', address: '广州', goods: '彩电', price: '4599', sales: 562, del: '', link: "<a href='handsontable_1.htm' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-01', address: '深圳', goods: '热水器', price: '1099', sales: 430, del: '', link: "<a href='http://www.baidu.com' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-02', address: '重庆', goods: '笔记本电脑', price: '4999', sales: 666, del: '', link: "<a href='handsontable_1.htm' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-02', address: '厦门', goods: '油烟机', price: '2899', sales: 438, del: '', link: "<a href='http://www.baidu.com' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-02', address: '青岛', goods: '饮水机', price: '899', sales: 620, del: '', link: "<a href='handsontable_1.htm' target='_blank' style='cursor:pointer;'>链接</a>" },
{ riqi: '2017-02', address: '大连', goods: '手机', price: '1999', sales: 500, del: '', link: "<a href='http://www.baidu.com' target='_blank' style='cursor:pointer;'>链接</a>" }
]; function negativeValueRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if (prop == 'address') {
td.style.color = '#32CD32';
}
else if (prop == 'price') {
//格式化价格数据
td.innerText = value != null ? numbro(value).format('0.00') : "";
}
else if (prop == 'sales') {
//右对齐
td.style.textAlign = 'right';
td.innerText = value != null ? numbro(value).format('0,0.00') : "";
}
else if (prop == 'del') {
//添加自定义的图片,并给图片的chick添加事件
var escaped = Handsontable.helper.stringify(value),
imgdel; imgdel = document.createElement('IMG');
imgdel.src = "handsontable/remove.png";
imgdel.width = 20;
imgdel.name = escaped;
imgdel.style = 'cursor:pointer;';//鼠标移上去变手型
Handsontable.dom.addEvent(imgdel, 'click', function (event) {
hot.alter("remove_row", row);//删除当前行
}); Handsontable.dom.empty(td);
td.appendChild(imgdel);
td.style.textAlign = 'center';
return td;
}
else if (prop == 'link') {
td.innerHTML = value;//字符串转化成HTML的写法
}
}
Handsontable.renderers.registerRenderer('negativeValueRenderer', negativeValueRenderer); var hot = new Handsontable(document.getElementById('example'), {
data: data,
colHeaders: ['操作', '日期', '地点', '商品', '单价', '销量','跳转'], // 使用自定义列头
rowHeaders: true,
colWidths: 150, // 设置所有列宽为150像素
filters: true,
columnSorting: true,
sortIndicator: true,
autoColumnSize: true,
manualColumnResize: true,
undo: true,
redo: true,
wordWrap: true,
copyable: true,
mergeCells: false,
manualRowResize: true,
manualRowMove: true,
manualColumnMove: false,
renderAllRows: true,
allowInsertRow: true,
allowInsertColumn: false,
fixedColumnsLeft: 1,
columns: [{
data: 'del',
type: 'text'
}, {
data: 'riqi',
type: 'date',
dateFormat: 'YYYY-MM-DD'
}, {
data: 'address',
type: 'text'
}, {
data: 'goods',
type: 'text'
}, {
data: 'price',
type: 'numeric'
}, {
data: 'sales',
type: 'numeric'
}, {
data: 'link',
type: 'text'
}],
contextMenu: ['row_above', 'row_below', '---------', 'remove_row', '---------', 'undo', 'redo', '---------', 'make_read_only', '---------', 'alignment'],
dropdownMenu: ['filter_by_condition', 'filter_by_value', 'filter_action_bar'],
cells: function (row, col, prop) {
var cellProperties = {};
cellProperties.renderer = "negativeValueRenderer";
return cellProperties;
},
});
</script>
</body>
</html>

  需要注意的是,不管link中的值是前台拼接还是后台处理好返回的,只是一个超链接格式的字符串,如果没有td.innerHTML = 链接字符串;则显示的仍然是一个字符串而不是超链接。

By QJL

Handsontable添加超链接的更多相关文章

  1. C#在excel中添加超链接

    1.新建一个项目 2.给项目添加引用:Microsoft Excel 12.0 Object Library (2007版本) using Excel = Microsoft.Office.Inter ...

  2. TextView 中添加超链接

    在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现   代码如下:    第一种    pu ...

  3. android textView 添加超链接(两种实现方式)

    在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现 在textView添加超链接,有两种方式 ...

  4. Flex4 中<s:Datagrid>、<mx:Datagrid>添加超链接的完整方法

    <s:Datagrid>的添加超链接方法(链接文字会重叠) <s:GridColumn dataField="_fileName" headerText=&quo ...

  5. 给TextView添加超链接的四种方式

    因为在上上篇博客中介绍了SpannableString的使用(SpannableString使用详解),由此想到给TextView添加超链接究竟有多少种方式?经过个人总结,现在一共发现四种,如果还有其 ...

  6. Android(java)学习笔记147:textView 添加超链接(两种实现方式,,区别于WebView)

    1.方式1: LinearLayout layout = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLa ...

  7. Django编写RESTful API(五):添加超链接提高模型间的关联性

    前言 在第四篇中,加入了用户模型,以及相关的认证和权限的功能.但是我们在使用的时候,会发现在访问http://127.0.0.1:8000/users/时看到的用户列表,不能够直接点击某个链接然后查看 ...

  8. C#/VB.NET对EXCEL图片添加超链接

    在日常工作中,在编辑文档时,为了方便自己或者Boss能够实时查看到需要的网页或者文档是,需要对在Excel中输入的相关文字进行超链接,那么对于一些在Excel中插入的图片我们该怎么实现超链接呢,下面给 ...

  9. Java 在PDF 中添加超链接

    对特定元素添加超链接后,用户可以通过点击被链接的元素来激活这些链接,通常在被链接的元素下带有下划线或者以不同的颜色显示来进行区分.按照使用对象的不同,链接又可以分为:文本超链接,图像超链接,E-mai ...

随机推荐

  1. CodeForces - 551C 二分+贪心

    题意:有n个箱子形成的堆,现在有m个学生,每个学生每一秒可以有两种操作: 1: 向右移动一格 2: 移除当前位置的一个箱子 求移除所有箱子需要的最短时间.注意:所有学生可以同时行动. 思路:二分时间, ...

  2. C. Vasya and String

    原题链接 C. Vasya and String High school student Vasya got a string of length n as a birthday present. T ...

  3. 关于使用srping @RequestParam 容易出错的地方

    大家都知道,在spring中的@RequestParam主要用户传递参数用的,具体的解释就是将请求参数去数据映射到功能处理方法的参数上.其中包括三个参数: value:参数名字,即入参的请求参数名字, ...

  4. Nginx 开启gzip压缩(图片,文件,css)

    1.Vim打开Nginx配置文件 vim /usr/local/nginx/conf/nginx.conf 2.找到如下一段,进行修改 gzip on; gzip_min_length 1k; gzi ...

  5. hive: insert数据时Error during job, obtaining debugging information 以及beyond physical memory limits

    insert overwrite table canal_amt1...... 2014-10-09 10:40:27,368 Stage-1 map = 100%, reduce = 32%, Cu ...

  6. Android学习开发中如何保持API的兼容

    Android学习开发中如何保持API的兼容: 1,采用良好的设计思路 在设计过程中,如果能按照下面的方式来进行设计,会让这个API生命更长久 面向用例的设计,收集用户建议,把自己模拟成用户,保证AP ...

  7. java 8 Lambda表达式(翻译自Stackoverflow)

    (原文链接)Lambda只能作用于一个只有一个抽象方法的函数式接口(Function Interface),不过函数式接口可以有任意数量default或static修饰的方法(因此,它们有时也被当做单 ...

  8. 3.1 PCI设备BAR空间的初始化

    在PCI Agent设备进行数据传送之前,系统软件需要初始化PCI Agent设备的BAR0~5寄存器和PCI桥的Base.Limit寄存器.系统软件使用DFS算法对PCI总线进行遍历时,完成这些寄存 ...

  9. 如何编译linux第一个模块 hellomod.ko

    Linux下的驱动程序也没有听上去的那么难实现,我们可以看一下helloworld这个例子就完全可以了解它的编写的方式! 我们还是先看一个这个例子,helloworld 1. [代码]hellowor ...

  10. 工作中常用的linux命令(2)

    1.find :查找指定文件名的路径: 列出当前目录以及子目录中的所有文件: 在当前目录下寻找特定文件名的文件: 列出长度为零的文件: 2.ps :查看某个程序的进程,例如查询mongodb和mysq ...