我有一个函数可以将我的单元格锁定在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;
},
答案 0 :(得分:0)
这似乎是JavaScript中的一个非常基本的问题。我建议你google搜索"加载事件js"," Javascript在页面加载后执行"等等。
除非你在handsontable
中寻找一种特定的方法,否则它可能与它们的钩子有关。有关详细信息,请look it up in the documentation。
答案 1 :(得分:0)
如果您想要做的是在加载页面后更改cells
定义,您可以随时使用
hotInstance.updateSettings({
cells: newCells // where newCells is a new set of conditionals
})
你可以在
中触发$(docuemnt).ready(function(){ // updateSettings });