【问题标题】:Function of handsontable only when the page is loaded只有页面加载时handsontable的功能
【发布时间】: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 它不能工作,因为它是元素初始化中的一个可操作的函数。我为您编辑过,我无法使用该事件:/

标签: javascript handsontable


【解决方案1】:

这似乎是 JavaScript 中一个非常基本的问题。我建议你在谷歌上搜索“加载事件 js”、“页面加载后执行 Javascript”等。

除非您在handsontable 中寻找特定的方法,在这种情况下,它可能与他们的钩子有关。欲了解更多信息,look it up in the documentation

【讨论】:

  • 我已经查看了文档,这就是我问这个问题的原因;)
【解决方案2】:

如果您想要在页面加载后更改 cells 定义,您可以随时使用更新它

hotInstance.updateSettings({
    cells: newCells // where newCells is a new set of conditionals
})

你可以在里面触发这个

$(docuemnt).ready(function(){ // updateSettings });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    相关资源
    最近更新 更多