本文在上文的基础上,返回的数据中多了一个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. 二、Item Pipeline和Spider-----基于scrapy取校花网的信息

    Item Pipeline 当Item在Spider中被收集之后,它将会被传递到Item Pipeline,这些Item Pipeline组件按定义的顺序处理Item. 每个Item Pipeline ...

  2. mongodb的TTL索引介绍(超时索引)

    TTL索引是mongodb新支持的用于延时自动删除记录的一种索引.它仅包含一个字段,该字段值需要是Date()类型,并且不支持复合索引.可以指定某条记录在延时固定时间后自动删除.数据自动超时删除主要用 ...

  3. Yii2 Restful Api 401

    采用Yii2 Restful Api方式为APP提供数据,默认你已经做好了所有的编码和配置工作.采用Postman测试接口: 出现这个画面的一个可能原因是:access_token的写法有误,如果你使 ...

  4. MySQL 之 视图、触发器、存储过程、函数、事物与数据库锁

    浏览目录: 1.视图 2.触发器 3.存储过程 4.函数 5.事物 6.数据库锁 7.数据库备份 1.视图 视图:是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据 视 ...

  5. UVA - 11636 Hello World! (贪心)

    思路:复制次数最少并且可以部分复制,那么贪心地让当前尽量多的复制,如果最后一次复制会超过n,那就部分复制.即满足并且x尽量小. AC代码 #include <stdio.h> const ...

  6. 我的Java设计模式-策略模式

    今天给大家说说田忌赛马的故事.如有雷同,纯属巧合!话说在战国时期,群雄割据,硝烟四起,茶余饭后还是少不了娱乐活动的,其中赛马是最火爆的.一天,孙膑看到田忌像个死鸡似的就知道肯定赛马又输给了齐威王,立马 ...

  7. U-boot-1.1.4中关于hello_world.srec出错

    make[1]: *** No rule to make target `hello_world.srec', needed by `all'.  Stop. make[1]: Leaving dir ...

  8. DOS下串口通信程序来传送文件的源代码

    接收程序: #include <dos.h>#include <fstream.h>#include <conio.h>#include <stdio.h&g ...

  9. 使用WinDbg内核调试

    首先你要配置好测试环境:参考VMware+Windgb+Win7 内核驱动调试 在你的主机上配置Symbols 配置sympath,C:\Users\Admin\Desktop\first\objch ...

  10. Eviews 9.0新版本新功能——预测(Auto-ARIMA预测、VAR预测)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 9.预测功能 新增需要方法的预测功能:Auto ...