在单元格中呈现自定义的元素:不能使用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. mac电脑安装selenium 记录

    1.使用终端去命令安装 sudo easy_install selenium 参考:https://www.cnblogs.com/nichoc/p/5543654.html 2.听说驱动放在 /us ...

  2. thinkPHP volist标签循环输出多维数组

    <volist name="company" id="vo">{$vo.company_name}<volist name="vo[ ...

  3. thinkphp5中Indirect modification of overloaded element of XXX has no effect的解决办法

    最近在使用Thinkphp5做foreach循环嵌套的时候报错:Indirect modification of overloaded element of XXX has no effect,网上搜 ...

  4. 496. Next Greater Element I + 503. Next Greater Element II + 556. Next Greater Element III

    ▶ 给定一个数组与它的一个子列,对于数组中的一个元素,定义它右边第一个比他大的元素称为他的后继,求所给子列的后继构成的数组 ▶ 第 496 题,规定数组最后一个元素即数组最大元素的后继均为 -1 ● ...

  5. 高斯白噪声(white Gaussian noise,WGN)

    本文科普一下高斯白噪声(white Gaussian noise,WGN). 百度百科上解释为“高斯白噪声,幅度分布服从高斯分布,功率谱密度服从均匀分布”,听起来有些晦涩难懂,下面结合例子通俗而详细地 ...

  6. Java——复制txt文件

    将源文件复制到目标文件,同时输出源文件内容,需要提供一个源文件和目标文件路径参数(如果不存在则自动创建) public static void copyTxt(String sourceFile, S ...

  7. GridEh Lookup

    Flexible adjustment of a lookup inplace editor 没有输入拼音码搜索功能. Drop-Down Forms 这个比较符合中国人的习惯,搜索框,不错,点下来箭 ...

  8. XE: Changing the default http port

    Oracle XE uses the embedded http listener that comes with the XML DB (XDB) to serve http requests. T ...

  9. 【python】 time模块和datetime模块详解 【转】

    一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...

  10. 使用ES(elasticsearch) 搜索引擎

    介绍  https://blog.csdn.net/andyzhaojianhui/article/details/75195296 创建语句 { "company":{ &quo ...