Handsontable添加超链接
本文在上文的基础上,返回的数据中多了一个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添加超链接的更多相关文章
- C#在excel中添加超链接
1.新建一个项目 2.给项目添加引用:Microsoft Excel 12.0 Object Library (2007版本) using Excel = Microsoft.Office.Inter ...
- TextView 中添加超链接
在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现 代码如下: 第一种 pu ...
- android textView 添加超链接(两种实现方式)
在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现 在textView添加超链接,有两种方式 ...
- Flex4 中<s:Datagrid>、<mx:Datagrid>添加超链接的完整方法
<s:Datagrid>的添加超链接方法(链接文字会重叠) <s:GridColumn dataField="_fileName" headerText=&quo ...
- 给TextView添加超链接的四种方式
因为在上上篇博客中介绍了SpannableString的使用(SpannableString使用详解),由此想到给TextView添加超链接究竟有多少种方式?经过个人总结,现在一共发现四种,如果还有其 ...
- Android(java)学习笔记147:textView 添加超链接(两种实现方式,,区别于WebView)
1.方式1: LinearLayout layout = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLa ...
- Django编写RESTful API(五):添加超链接提高模型间的关联性
前言 在第四篇中,加入了用户模型,以及相关的认证和权限的功能.但是我们在使用的时候,会发现在访问http://127.0.0.1:8000/users/时看到的用户列表,不能够直接点击某个链接然后查看 ...
- C#/VB.NET对EXCEL图片添加超链接
在日常工作中,在编辑文档时,为了方便自己或者Boss能够实时查看到需要的网页或者文档是,需要对在Excel中输入的相关文字进行超链接,那么对于一些在Excel中插入的图片我们该怎么实现超链接呢,下面给 ...
- Java 在PDF 中添加超链接
对特定元素添加超链接后,用户可以通过点击被链接的元素来激活这些链接,通常在被链接的元素下带有下划线或者以不同的颜色显示来进行区分.按照使用对象的不同,链接又可以分为:文本超链接,图像超链接,E-mai ...
随机推荐
- 初识vue——起步
一.目录结构: 我们经常使用的是以下几个目录: 1.assets:静态资产文件:在vue组件中,所有组件中,所有模板和CSS都会被vue-html-loader和css-loader解析,并查找资源u ...
- crontab定时任务(centos)
cron服务是Linux的内置服务,但它不会开机自动启动.可以用以下命令启动和停止服务: /sbin/service crond start /sbin/service crond stop /sbi ...
- soj1091 指环王 bfs+hash+剪枝
原题链接http://acm.scu.edu.cn/soj/problem.action?id=1091 这题的主要解法就是搜索,我用的是bfs,用map将二维数组处理成字符串作为主键,到达当前状态的 ...
- yaf代码生成工具的使用
具体步骤如下: 1.下载php-yaf源码: git clone https://github.com/laruence/php-yaf/ 2.运行代码生成工具: /Users/helloxiaozh ...
- 读取含有BOM头的文件遇到的问题
需求是读取一个csv文件,然后解析成对应的数据结构.csv必须包含指定的某些列,通过列名header来进行校验. 解析配置文件的方法. public List<QuestionData> ...
- FFMpeg.H264解码win开发环境搭建
开发环境: vc6.0 + sp5 + vcpp5,注意vcpp5在vc6+sp6上会安装失败. 源码: ff_264_dec_vc,可用vc进行编译调试,但编译环境限定如上. 声明:该工程是ffmp ...
- hi3531串口波特率计算
波特率配置 通过配置寄存器UART_IBRD 和UART_FBRD 可以设置UART 工作的波特率,波特率 计算公式为: 当前波特率=UART 参考时钟频率(1/2 总线时钟频率)/(16 x 分频系 ...
- List转换成JSON对象报错(二)
List转换成JSON对象 1.具体报错如下 Exception in thread "main" java.lang.NoClassDefFoundError: org/apac ...
- const char *p;和char * const p的区别
const char *p; const修饰*p,所以*p是一个常量,不可修改. char* const p; const修饰p,所以指针p是一个常量,不可修改. #include< ...
- MTBF
MTBF,即平均故障间隔时间,英文全称是"Mean Time Between Failure".是衡量一个产品(尤其是电器产品)的可靠性指标.单位为"小时".它 ...