handsontable-cell features
数据验证:在columns中设置validator,进行同步或异步验证,还可添加beforeValidate, afterValidate函数,allowInvalid:true可以不用验证
var people = [
{id: 1, name: {first: 'Joe', last: 'Fabiano'}, ip: '0.0.0.1', email: 'Joe.Fabiano@ex.com'},
{id: 2, name: {first: 'Fred', last: 'Wecler'}, ip: '0.0.0.1', email: 'Fred.Wecler@ex.com'},
{id: 3, name: {first: 'Steve', last: 'Wilson'}, ip: '0.0.0.1', email: 'Steve.Wilson@ex.com'},
{id: 4, name: {first: 'Maria', last: 'Fernandez'}, ip: '0.0.0.1', email: 'M.Fernandez@ex.com'},
{id: 5, name: {first: 'Pierre', last: 'Barbault'}, ip: '0.0.0.1', email: 'Pierre.Barbault@ex.com'},
{id: 6, name: {first: 'Nancy', last: 'Moore'}, ip: '0.0.0.1', email: 'Nancy.Moore@ex.com'},
{id: 7, name: {first: 'Barbara', last: 'MacDonald'}, ip: '0.0.0.1', email: 'B.MacDonald@ex.com'},
{id: 8, name: {first: 'Wilma', last: 'Williams'}, ip: '0.0.0.1', email: 'Wilma.Williams@ex.com'},
{id: 9, name: {first: 'Sasha', last: 'Silver'}, ip: '0.0.0.1', email: 'Sasha.Silver@ex.com'},
{id: 10, name: {first: 'Don', last: 'Pérignon'}, ip: '0.0.0.1', email: 'Don.Pérignon@ex.com'},
{id: 11, name: {first: 'Aaron', last: 'Kinley'}, ip: '0.0.0.1', email: 'Aaron.Kinley@ex.com'}
],
example1 = document.getElementById('example1'),
example1console = document.getElementById('example1console'),
settings1,
ipValidatorRegexp,
emailValidator; ipValidatorRegexp = /^(?:\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b|null)$/;
emailValidator = function (value, callback) {
setTimeout(function(){
//还能这样验证
if (/.+@.+/.test(value)) {
callback(true);
}
else {
callback(false);
}
}, 1000);
}; settings1 = {
data: people,
//hooks
beforeChange: function (changes, source) {
//changes是数组,数组的元素也是数组,包含四个属性0:10,1:'name.last',2:'Kinley',3:'foo'
for (var i = changes.length - 1; i >= 0; i--) {
// gently don't accept the word "foo" (remove the change at index i)
//如果想改为foo,会把这次修改删掉
if (changes[i][3] === 'foo') {
changes.splice(i, 1);
}
// if any of pasted cells contains the word "nuke", reject the whole paste
//如果想改为nuke,只是拒绝,而不会删除此次修改
else if (changes[i][3] === 'nuke') {
return false;
}
// capitalise first letter in column 1 and 2
else if ((changes[i][1] === 'name.first' || changes[i][1] === 'name.last') && changes[i][3].charAt(0)) {
changes[i][3] = changes[i][3].charAt(0).toUpperCase() + changes[i][3].slice(1);
}
}
},
afterChange: function (changes, source) {
if (source !== 'loadData') {
example1console.innerText = JSON.stringify(changes);
}
},
colHeaders: ['ID', 'First name', 'Last name', 'IP', 'E-mail'],
columns: [
{data: 'id', type: 'numeric'},
{data: 'name.first'},
{data: 'name.last'},
//给ip加事件处理程序,可以不通过验证
{data: 'ip', validator: ipValidatorRegexp, allowInvalid: true},
{data: 'email', validator: emailValidator, allowInvalid: false}
]
};
var hot = new Handsontable(example1, settings1);
往下拖
var
data = [
['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
['2012', 10, 11, 12, 13],
['2013', 20, 11, 14, 13],
['2014', 30, 15, 12, 13],
['2015', '', '', '', ''],
['2016', '', '', '', '']
],
container = document.getElementById('example1'),
hot1; hot1 = new Handsontable(container, {
rowHeaders: true,
colHeaders: true,
//默认为true,如果为"horizontal",则只能水平拖动
fillHandle: true // possible values: true, false, "horizontal", "vertical"
});
hot1.loadData(data);
合并单元格
var
container = document.getElementById('example1'),
hot; hot = new Handsontable(container, {
data: Handsontable.helper.createSpreadsheetData(100, 18),
colWidths: [47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47],
rowHeaders: true,
colHeaders: true,
contextMenu: true,
//使用mergeCells提供合并单元格的细节
mergeCells: [
{row: 1, col: 1, rowspan: 3, colspan: 3},
{row: 3, col: 4, rowspan: 2, colspan: 2},
{row: 5, col: 6, rowspan: 3, colspan: 3}
]
});
布局:在cell中设置位置;水平方向:htLeft, htCenter, htRight, htJustify;垂直方向:htTop, htMiddle, htBottom
var
container = document.getElementById('example1'),
hot1; hot1 = new Handsontable(container, {
data: Handsontable.helper.createSpreadsheetData(100, 18),
colWidths: [47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47],
rowHeaders: true,
colHeaders: true,
contextMenu: true,
mergeCells: [
{row: 1, col: 1, rowspan: 3, colspan: 3},
{row: 3, col: 4, rowspan: 2, colspan: 2}
],
//预定义了很多类
className: "htCenter",
cell: [
{row: 0, col: 0, className: "htRight"},
{row: 1, col: 1, className: "htLeft htMiddle"},
{row: 3, col: 4, className: "htLeft htBottom"}
],
//在这个hooks中,可以捕获到布局的改变
afterSetCellMeta: function (row, col, key, val) {
console.log("cell meta changed", row, col, key, val);
}
});
列和单元格的只读属性
var
container1 = document.getElementById('example1'),
hot1; hot1 = new Handsontable(container1, {
data: getCarData(),
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
columns: [
{
data: 'car',
//列只读
readOnly: true
},
{
data: 'year'
},
{
data: 'chassis'
},
{
data: 'bumper'
}
]
});
//单元格只读
var
container2 = document.getElementById('example2'),
hot2; hot2 = new Handsontable(container2, {
data: getCarData(),
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'] });
hot2.updateSettings({
cells: function (row, col, prop) {
var cellProperties = {}; if (hot2.getData()[row][prop] === 'Nissan') {
cellProperties.readOnly = true;
} return cellProperties;
}
})
列和单元格不可编辑:non-edit cell仍然可以拖动填充,复制粘贴,只是不能编辑;只读属性:不能做任何操作
var
container1 = document.getElementById('example1'),
hot1; hot1 = new Handsontable(container1, {
data: getCarData(),
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
columns: [
{
data: 'car',
editor: false
},
{
data: 'year',
editor: 'numeric'
},
{
data: 'chassis',
editor: 'text'
},
{
data: 'bumper',
editor: 'text'
}
]
});
var
container2 = document.getElementById('example2'),
hot2; hot2 = new Handsontable(container2, {
data: getCarData(),
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color']
});
hot2.updateSettings({
cells: function (row, col, prop) {
var cellProperties = {}; if (hot2.getData()[row][prop] === 'Nissan') {
cellProperties.editor = false;
} else {
cellProperties.editor = 'text';
} return cellProperties;
}
})
handsontable-cell features的更多相关文章
- Codeforces 549D. Hear Features[贪心 英语]
D. Haar Features time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 转:Busy Developers' Guide to HSSF and XSSF Features
Busy Developers' Guide to Features Want to use HSSF and XSSF read and write spreadsheets in a hurry? ...
- Looksery Cup 2015 D. Haar Features 暴力
D. Haar Features Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/prob ...
- 1.6.3 Uploading Data with Solr Cell using Apache Tika
1. Uploading Data with Solr Cell using Apache Tika solr使用Apache Tika工程的代码提供了一个框架,用于合并所有不同格式的文件解析器为so ...
- Handsontable 学习笔记-Methods
Handson: 亲自实践 先给出数据源和基本配置: var data =[ ["A1","B1","C1","D1"] ...
- Handsontable对单元格的操作
1.自动填充单元格数据 fillHandle:true/false //当值为true时,允许拖动单元格右下角,将其值自动填充到选中的单元格 2.合并单元格 mergeCells:[{row:起 ...
- handsontable 合并单元格
<!DOCTYPE html> <html> <head> <title>handsontable demo</title> <met ...
- handsontable 属性汇总
常规属性: 1.固定行列位置 fixedRowsTop:行数 //固定顶部多少行不能垂直滚动 fixedColumnsLeft:列数 //固定左侧多少列不能水平滚动 2.拖拽行头或列头改变行或列的大小 ...
- ADF BC New Features
Examining ADF Business Components New Features Purpose In this tutorial, you create a series of si ...
- handsontable 常用 配置项 笔记
import React, { Component } from 'react'; import HotTable from 'react-handsontable'; import Handsont ...
随机推荐
- 【python】常用的日期和时间操作
#-*- coding: utf-8 -*- import datetime #给定日期向后N天的日期 def dateadd_day(days): d1 = datetime.datetime.no ...
- Python自然语言处理(1):初识NLP
由于我们从美国回来就是想把医学数据和医学人工智能的事认真做起来,所以我们选择了比较扎实的解决方法,想快速出成果的请绕道.我们的一些解决方法是:1.整合公开的所有医学词典,尽可能包含更多的标准医学词汇: ...
- PHP常用获取文件路径的函数集合整理
转自: http://blog.sina.com.cn/s/blog_71ed1b870102vslg.html 我们在开发PHP项目过程中,经常会用到包含文件,所以有时候需要获取文件的相对路径或者绝 ...
- 32位汇编基础_内存_每个应用进程都会有自己独立的4GB内存空间
1.每个应用进程都会有自己独立的4GB内存空间 这句话很多人听起来可能会很矛盾很不解. 例如,我的电脑只有2GB的内存,打开个软件机会占用4GB内存,而我的电脑内存只有2GB,显然不够用,但是为什么程 ...
- usaco 2009 12 过路费
最近学的图论,oj上的这道题卡了我一上午,写一下总结. 题目描述: 跟所有人一样,农夫约翰以着宁教我负天下牛,休教天下牛负我(原文:宁我负人,休教人负我)的伟大精神,日日夜夜苦思生财之道.为了发财,他 ...
- java程序调优系列(一)intern()代替equal()
1. 首先String不属于8种基本数据类型,String是一个对象. 因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些特性. 2. ne ...
- linux下python3离线加载nltk_data,不用nltk.download()
在不能上网的服务器上把nltk_data关联到python3,已经安装anaconda3所以不需要安装nltk,环境是linux 首先没有nltk_data在使用nltk会报错 LookupError ...
- ES6系列_7之箭头函数和扩展
1.默认值 在ES6中给我们增加了默认值的操作相关代码如下: function add(a,b=1){ return a+b; } console.log(add(1)); 可以看到现在只需要传递一个 ...
- 在 ubuntu1604 中 搭建 i 屁 sec 虚拟专用连接服务器
1.wget https://git.io/vpnsetup -O vpnsetup.sh 2.vim vpnsetup.sh 修改一些内容: 主要有三个参数:IPSEC的预共享秘钥,用户名,密码 3 ...
- VMware CentOS Device eth0 does not seem to be present
在VMware里克隆出来的CentOS Linux.. ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting ...