【发布时间】:2015-09-04 23:51:47
【问题描述】:
我有一个功能可以将我的单元格锁定在handsontable 中,但我只想在页面加载时锁定它们。
cells:function(row,col,prop){ //Fonctions pour bloquer les cellules
var cellProperties = {};
if ([0].indexOf(row) !== -1 && col >= 0)
{
cellProperties.readOnly = true;
cellProperties.renderer = firstRowRenderer;
}
if(([0].indexOf(col) == 0) && (data_itk_pro_update[row][0]) && flag==true) //Here is the function to block the first column
{
cellProperties.readOnly = true;
}
if(([1].indexOf(col) == 0) && (data_itk_pro_update[row][1]) && flag==true)
{
cellProperties.readOnly = true;
}
if (readOnlyCellsITKPROU[[row,col]]) {
cellProperties.readOnly = true;
}
return cellProperties;
},
当用户在新行中插入数据时,我不希望新单元格被阻止。所以我想到了这样一个条件:
如果页面正在加载
但我不知道该怎么做。而且我不知道prop的用处。
有人可以帮帮我吗?
编辑:我尝试了几件事:
if (document.readyState === "complete") {
..
$(window).load(function () {
..
window.onload = function () {
..
if(window.onload){
EDIT2:
我的元素的整个初始化:
var container = document.getElementById('tab_itk_pro_modif');
var hotITKPROU = new Handsontable(container, {
data: data_itk_pro_update,
minSpareRows: 1,
fixedRowsTop : 1,
rowHeaders: false,
colHeaders: false,
contextMenu: {
items: {
"remove_row": {
name: 'Supprimer la ligne',
disabled: function () {
return hotITKPROU.getSelected()[0] === 0
}
}
}
},
cells:function(row,col,prop){ //Fonctions pour bloquer les cellules
var cellProperties = {};
if ([0].indexOf(row) !== -1 && col >= 0) //Pour bloquer la première ligne
{
cellProperties.readOnly = true;
cellProperties.renderer = firstRowRenderer;
}
if(([0].indexOf(col) == 0) && (data_itk_pro_update[row][0]) && flag==true)
{
cellProperties.readOnly = true;
}
if(([1].indexOf(col) == 0) && (data_itk_pro_update[row][1]) && flag==true)
{
cellProperties.readOnly = true;
}
if (readOnlyCellsITKPROU[[row,col]]) { //Pour bloquer les composants des id concaténés
cellProperties.readOnly = true;
}
return cellProperties;
},
【问题讨论】:
-
已经存在一个stackoverflow问题:stackoverflow.com/questions/9899372/…
-
@JoshSpears 我看过,但它不是同一个应用程序。我不能在handsontable中使用类似的东西:/
-
你在用jquery吗?
-
$(docuemnt).ready(function(){ //your code here }); -
@JoshSpears 它不能工作,因为它是元素初始化中的一个可操作的函数。我为您编辑过,我无法使用该事件:/