在单元格中呈现自定义的元素:不能使用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>.",
     //'★★★★&#x2606'
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的更多相关文章

  1. 文献导读 | 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. 首先要考虑样本的选择,样本里是否存在明显的分层 ...

  2. Advances in Single Cell Genomics to Study Brain Cell Types | 会议概览

    单细胞在脑科学方面的应用 Session 1: Deciphering the Cellular Landscape of the Brain Using Single Cell Transcript ...

  3. 如何使用masonry设计复合型cell[转]

    前言 其实早在@sunnyxx同学发布UIView-FDCollapsibleConstraints的时候 我就说要写一下怎么用代码来稍微麻烦的实现复用的问题 但是一直各种没时间(主要是我的办法太复杂 ...

  4. 使用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 ...

  5. cell 配置

    Cells Cell configuration options Configure the API (top-level) cell Configure the child cells Config ...

  6. 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 ...

  7. 单细胞分析实录(1): 认识Cell Hashing

    这是一个新系列 差不多是一年以前,我定导后没多久,接手了读研后的第一个课题.合作方是医院,和我对接的是一名博一的医学生,最开始两边的老师很排斥常规的单细胞文章思路,即各大类细胞分群.注释.描述,所以起 ...

  8. handsontable-developer guide-cell function

    renderer 展示的数据不是来自于数据源,而是先把DOM和其他信息传给renderer,然后展示. //五种展示函数 TextRenderer: default NumericRenderer A ...

  9. 基于NPOI的Excel数据导入

    从Excel导入数据最令人头疼的是数据格式的兼容性,特别是日期类型的兼容性.为了能够无脑导入日期,折腾了一天的NPOI.在经过测试确实可以导入任意格式的合法日期后,写下这篇小文,与大家共享.完整代码请 ...

随机推荐

  1. Windows应用程序的VC链接器设置

    Windows应用程序的VC链接器设置 /*转载请注明出自 听风独奏 www.GbcDbj.com */ Windows应用程序分为GUI(Graphical User Interface)和CUI( ...

  2. IE11浏览器卸载

    点击卸载程序,然后选择查看已安装的更新. 在当前安装的更新里找到IE11的更新,然后直接右击卸载:这里告诉大家一小窍门哈,我们在搜索栏输入IE就会查找更新啦,不用一个一个去找的哦. 卸载完我们重启一下 ...

  3. logger 的使用 二logback使用配置详解

    下面是一些最基本的,详细的参考:https://logback.qos.ch/manual/index.html 我的使用:把error日志打印在另一个文件,可以用ELK 统一管理 最近使用: < ...

  4. Rhythmk 一步一步学 JAVA (21) JAVA 多线程

    1.JAVA多线程简单示例 1.1 .Thread  集成接口 Runnable 1.2 .线程状态,可以通过  Thread.getState()获取线程状态: New (新创建) Runnable ...

  5. Lazy JSF Primefaces Datatable Pagination

    http://www.javacodegeeks.com/2012/04/lazy-jsf-primefaces-datatable.html

  6. windows到ubuntu

    按照xmarks同步浏览器书签. mvn, copy setting.xml 最好不要用apt-get install maven, 占用/的磁盘空间 mvn -U package -P"d ...

  7. ELK Stack 5.2.2 安装文档

    简介: ELK Stack 安装文档,这次都使用最新版本(5.2.2).RPM 包的方式搭建 ELK Stack. 下载地址: https://artifacts.elastic.co/downloa ...

  8. 使用opencv3+python实现视频运动目标检测

    本文主要实现了伯乐在线上的一个实践小项目,原文链接,用以巩固opencv视频操作知识内容.整个项目均有代码注释,通俗易懂,短短几十行就可以达到还算不错的实现效果,做起来成就感满满哒.打开编辑器,一起来 ...

  9. 取消Eclipse的Error Reporting

    选择Preferences->General->Error Reporting,Send Mode选择Never send reports

  10. LevelDB Version

    [LevelDB Version] Version 保存了当前磁盘以及内存中所有的文件信息,一般只有一个Version叫做"current" version(当前版本).Level ...