原文地址:http://blog.csdn.net/mafan121/article/details/46119905
1.自動填充單元格數據
fillHandle:true/false //當值為true時,允許拖動單元格右下角,將其值自動填充到選中的單元格
2.合並單元格
初始化配置:mergeCells:[{row:起始行數,cols:起始列數,rowspan:合並的行數,colspan:合並的列數},...]
或者初始化聲明:mergeCells:true //表示允許單元格合並
但單元格合並的操作,需如下操作:
- if(key == "merge") {
- if(hot.mergeCells.mergedCellInfoCollection.length > 0) {
- for(var k=0; k<hot.mergeCells.mergedCellInfoCollection.length; k++) {
- if(hot.mergeCells.mergedCellInfoCollection[k].row == row &&
- hot.mergeCells.mergedCellInfoCollection[k].col == col) {
- hot.mergeCells.mergedCellInfoCollection.splice(k,1);
- return;
- }else{
- hot.mergeCells.mergedCellInfoCollection.push({"row": row, "col": col,
- "rowspan": rowspan, "colspan": colspan});
- break;
- }
- }
- } else {
- hot.mergeCells.mergedCellInfoCollection.push({"row": row, "col": col, "rowspan": rowspan, "colspan": colspan});
- }
3.初始化單元格或列的對齊方式
水平樣式:htLeft,htCenter,htRight,htJustify
垂直樣式:htTop,htMiddle,htBottom
4.只讀模式
列只讀,設置列屬性:readOnly:true
單元格只讀:cellProperties.readOnly = true
5.設置單元格的編輯類型
columns:[{type:類型}]
主要的類型有:
text:字符串
numeric:數字類型
date:日期框
checkbox:單選框
password:密碼框
下面幾種類型的使用比較特殊
select:下拉編輯器
columns:[
{editor:'select',
selectOption:[選項1,選項2,...]},
.......
]
dropdown:下拉選擇
columns:[
{type:'dropdown',
source:[選項1,選項2,...]},
......
]
autocomplete:自動匹配模式
columns:[
{type:'autocomplete',
source:[選項1,選項2,...],
strict:true/false, //值為true,嚴格匹配
allowInvalid:true/false //值為true時,允許輸入值作為匹配內容,只能在strict為true時使用
},
......
]
handsontable:表格模式
columns:[
{type:'handsontable',
handsontable:{...},
......
]
自定義模式
data=[{
title:html標簽,
description:描述,
comments:評論,
cover:封面
},
......
]
自定義邊界
customBorders:[
range:{
form:{row:行數,col:列數}, //起始行列
to:{row:行數,col:列數}, //終止行列
top/bottom/right/left:{ //上下右左邊線
width:像數,
color:顏色
}
}
]
6.查詢單元格的值
查詢單元格的值需要3個步驟:
a.設置hot的屬性search為true
b.創建比對函數
c.渲染比對結果
示例代碼如下:
- var
- data = [
- ['Nissan', 2012, 'black', 'black'],
- ['Nissan', 2013, 'blue', 'blue'],
- ['Chrysler', 2014, 'yellow', 'black'],
- ['Volvo', 2015, 'yellow', 'gray']
- ],
- example = document.getElementById('example1'),
- searchFiled = document.getElementById('search_field'),
- hot;
- hot = new Handsontable(example, {
- data: data,
- colHeaders: true,
- search: true
- });
- function onlyExactMatch(queryStr, value) {
- return queryStr.toString() === value.toString();
- }
- Handsontable.Dom.addEvent(searchFiled, 'keyup', function (event) {
- var queryResult = hot.search.query(this.value);
- console.log(queryResult);
- hot.render();
- });
7.評論
comments:true/false //當值為true時可以顯示評論,右鍵菜單可添加刪除評論。
當值為true時,可設置單元格的評論內容,格式為:
cell:[
{
row:行數,
col:列數,
comment:評論內容
}
]