handsontable-cell type
在单元格中呈现自定义的元素:不能使用html元素
var
data = [
{
title: "<a href='http://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691'>Professional JavaScript for Web Developers</a>",
description: "This <a href='http://bit.ly/sM1bDf'>book</a> provides a developer-level introduction along with more advanced and useful features of <b>JavaScript</b>.",
//'★★★★☆'
comments: "I would rate it ★★★★☆",
cover: "http://ecx.images-amazon.com/images/I/51bRhyVTVGL._SL50_.jpg"
},
{
title: "<a href='http://shop.oreilly.com/product/9780596517748.do'>JavaScript: The Good Parts</a>",
description: "This book provides a developer-level introduction along with <b>more advanced</b> and useful features of JavaScript.",
comments: "This is the book about JavaScript",
cover: "http://ecx.images-amazon.com/images/I/51gdVAEfPUL._SL50_.jpg"
},
{
title: "<a href='http://shop.oreilly.com/product/9780596805531.do'>JavaScript: The Definitive Guide</a>",
description: "<em>JavaScript: The Definitive Guide</em> provides a thorough description of the core <b>JavaScript</b> language and both the legacy and standard DOMs implemented in web browsers.",
comments: "I've never actually read it, but the <a href='http://shop.oreilly.com/product/9780596805531.do'>comments</a> are highly <strong>positive</strong>.",
cover: "http://ecx.images-amazon.com/images/I/51VFNL4T7kL._SL50_.jpg"
}
],
container1,
hot1; container1 = document.getElementById('example1');
hot1 = new Handsontable(container1, {
data: data,
colWidths: [200, 200, 200, 80],
colHeaders: ["Title", "Description", "Comments", "Cover"],
columns: [
{data: "title", renderer: "html"},
{data: "description", renderer: "html"},
{data: "comments", renderer: safeHtmlRenderer},
{data: "cover", renderer: coverRenderer}
]
}); // original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// 只允许input中包含allowed中指定的标签
function strip_tags(input, allowed) {
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi; // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
});
} function safeHtmlRenderer(instance, td, row, col, prop, value, cellProperties) {
//这种方法我还没有用过
var escaped = Handsontable.helper.stringify(value);
escaped = strip_tags(escaped, '<em><b><strong><a><big>'); //be sure you only allow certain HTML tags to avoid XSS threats (you should also remove unwanted HTML attributes)
td.innerHTML = escaped; return td;
} function coverRenderer (instance, td, row, col, prop, value, cellProperties) {
var escaped = Handsontable.helper.stringify(value),
img; if (escaped.indexOf('http') === 0) {
img = document.createElement('IMG');
img.src = value; Handsontable.Dom.addEvent(img, 'mousedown', function (e){
//防止出现异常情况
e.preventDefault(); // prevent selection quirk
}); Handsontable.Dom.empty(td);
td.appendChild(img);
}
else {
// render as text
//如果不是http开头的话,当前的renderer就是用textrenderer
Handsontable.renderers.TextRenderer.apply(this, arguments);
} return td;
}
thead中呈现自定义元素:呈现自定义元素,都是通过renderer函数
var
isChecked,
container2 = document.getElementById('example2'),
hot2; hot2 = new Handsontable(container2, {
columns: [
{},
{renderer: customRenderer}
],
colHeaders: function (col) {
var txt; switch (col) {
case 0:
return '<b>Bold</b> and <em>Beautiful</em>'; case 1:
txt = "Some <input type='checkbox' class='checker' ";
txt += isChecked ? 'checked="checked"' : '';
txt += "> checkbox"; return txt;
}
}
}); function customRenderer(instance, td) {
Handsontable.renderers.TextRenderer.apply(this, arguments); if (isChecked) {
td.style.backgroundColor = 'yellow';
}
else {
td.style.backgroundColor = 'white';
} return td;
} Handsontable.Dom.addEvent(container2, 'mousedown', function (event) {
if (event.target.nodeName == 'INPUT' && event.target.className == 'checker') {
//阻止事件传播
event.stopPropagation();
}
}); Handsontable.Dom.addEvent(container2, 'mouseup', function (event) {
if (event.target.nodeName == 'INPUT' && event.target.className == 'checker') {
isChecked = !event.target.checked;
//调用customRenderer
hot2.render();
}
});
在thead中,通过下拉菜单,改变单元格的类型
cell type numeric:使用Numeral.js来进行格式化
cell type date:需要引入pikaday.js, pikaday.css, moment.js; 默认的格式是DD/MM/YYYY, 设置dateFormat和correctFormat之后,会改变
{
type: 'date',
dateFormat: 'MM/DD/YYYY',
correctFormat: true,
defaultDate: '01/01/1900'
},
checkbox:只有两个值(默认为true,false)的话,可以使用checkbox;如果想使用其他值的话
{
data: "comesInBlack",
type: "checkbox",
checkedTemplate: 'yes',
uncheckedTemplate: 'no'
}
select:双击之后,才会出现下拉菜单
{
editor: 'select',
selectOptions: ['Kia', 'Nissan', 'Toyota', 'Honda']
},
dropdown:不用双击,就能看到下拉菜单;跟autocomplete很像
{
type: 'dropdown',
source: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white']
},
//type:'dropdown' 相当于 type:'autocomplete', strict:true, filter:false
autocomplete:可以选择, 可以编辑
{
type: 'autocomplete',
source: ['BMW', 'Chrysler', 'Nissan', 'Suzuki', 'Toyota', 'Volvo'],
strict: false
},
//默认是lazy mode
strict
ajax
password:hashLenght:10:黑点相同,都有10个
handsontable
handsontable-cell type的更多相关文章
- 文献导读 | Single-Cell Sequencing of iPSC-Dopamine Neurons Reconstructs Disease Progression and Identifies HDAC4 as a Regulator of Parkinson Cell Phenotypes
文献编号:19Mar - 11 2019年04月23日三读,会其精髓: 相信这种方法的话,那么它的精髓是什么,如何整合出这个core gene set. 首先要考虑样本的选择,样本里是否存在明显的分层 ...
- Advances in Single Cell Genomics to Study Brain Cell Types | 会议概览
单细胞在脑科学方面的应用 Session 1: Deciphering the Cellular Landscape of the Brain Using Single Cell Transcript ...
- 如何使用masonry设计复合型cell[转]
前言 其实早在@sunnyxx同学发布UIView-FDCollapsibleConstraints的时候 我就说要写一下怎么用代码来稍微麻烦的实现复用的问题 但是一直各种没时间(主要是我的办法太复杂 ...
- 使用poi读取excel文件 Cannot get a text value from a numeric cell
我这样转换得到一个excel文本域的值 Cell cell = row.getCell(c); cell.setCellType(Cell.CELL_TYPE_STRING); String park ...
- cell 配置
Cells Cell configuration options Configure the API (top-level) cell Configure the child cells Config ...
- In Vitro model验证 | Harnessing single-cell genomics to improve the physiological fidelity of organoid-derived cell types
Transcriptional benchmarking of in vitro cells to in vivo with single-cell rna-seq - 简介 Harnessing s ...
- 单细胞分析实录(1): 认识Cell Hashing
这是一个新系列 差不多是一年以前,我定导后没多久,接手了读研后的第一个课题.合作方是医院,和我对接的是一名博一的医学生,最开始两边的老师很排斥常规的单细胞文章思路,即各大类细胞分群.注释.描述,所以起 ...
- handsontable-developer guide-cell function
renderer 展示的数据不是来自于数据源,而是先把DOM和其他信息传给renderer,然后展示. //五种展示函数 TextRenderer: default NumericRenderer A ...
- 基于NPOI的Excel数据导入
从Excel导入数据最令人头疼的是数据格式的兼容性,特别是日期类型的兼容性.为了能够无脑导入日期,折腾了一天的NPOI.在经过测试确实可以导入任意格式的合法日期后,写下这篇小文,与大家共享.完整代码请 ...
随机推荐
- Java 迭代器 Iterator
迭代器模式 迭代器模式(Iterator Pattern)是 Java 和 .Net 编程环境中非常常用的设计模式.这种模式用于顺序访问集合对象的元素,不需要知道集合对象的底层表示. 迭代器模式属于行 ...
- JVM体系结构之三:方法区之2(jdk1.6,jdk1.7,jdk1.8下的方法区变迁)
方法区 方法区存储虚拟机加载的类信息,常量,静态变量,即时编译器编译后的代码等数据.HotSpot中也称为永久代(Permanent Generation),(存储的是除了Java应用程序创建的对象之 ...
- 三.jQuery源码解析之jQuery的框架图
这张图片是对jQuery源码截图,一点一点拼出来的. 现在根据这张图片来对jQuery框架做一些说明. 一.16~9404行可以发现,最外层是一个自调用函数.当jQuery初始化时,这个自调用函数包含 ...
- Eclipse Android 代码自动提示功能 +导入 epf
1.设置 java 文件的代码提示功能 打 开 Eclipse 依次选择 Window > Preferences > Java > Editor - Content Assist ...
- 网页中显示pdf的方法
非常好的在网页中显示pdf的方法 今天有一需求,要在网页中显示pdf,于是立马开始搜索解决方案,无意中发现一个非常好的解决方法,详见http://blogs.adobe.com/pdfdevjunki ...
- PyQt5系列教程(三)用py2exe进行程序打包
软硬件环境 Windows 10 Python 3.4.2 PyQt5 Py2exe 前言 在我们开发了完整的PyQt5项目后,一般都会将其打包成exe文件,方便其他人使用.今天我们就用Py2exe这 ...
- Python Web框架——Flask
简介 Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求进行预处理 ...
- ImportError: Couldn't import Django.或者提示Django 模块不存在
ImportError: Couldn't import Django. 或者 多版本的python引起的,执行以下命令 即可解决问题 python3是新的版本的python python3 -m ...
- Visio2013 64位下载安装以及破解激活教程
特别说明:以下教程如果未能破解激活,请在断网条件下安装破解!!!! 安装: Visio2013 professional版下载地址:https://pan.baidu.com/s/1gzwcGTevV ...
- FoxPro 常用内部函数
1.数学函数(数值函数) 求绝对值函数ABS 格式:ABS( expN) 求整函数INT 格式:INT( expN) 四舍五入函数ROUND 格式:ROUND( expN,〈保留小数位〉) 功能:按保 ...