0

I have a function which locks my cells in handsontable but I want to lock them only when the page is loaded.

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;
                    },

When the user insert data in a new row, I don't want the new cells to be blocked. So I think about a condition like :

If the page is loading

But I don't know how to do. And I don't know the utility of prop.

Can someone help me please ?

EDIT : I tried several thing :

if (document.readyState === "complete")  {

..

 $(window).load(function () {

..

window.onload = function () {

..

if(window.onload){

EDIT2 :

The entire initialization of my element :

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;
                    },
Erlaunis
  • 1,433
  • 6
  • 32
  • 50
  • A stackoverflow question already exists for this: http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the – Josh Sep 03 '15 at 12:45
  • @JoshSpears I looked but it's not the same application. I can't use something like that with handsontable :/ – Erlaunis Sep 03 '15 at 12:56
  • Are you using jquery? – Josh Sep 03 '15 at 13:14
  • ```$(docuemnt).ready(function(){ //your code here });``` – Josh Sep 03 '15 at 13:15
  • @JoshSpears It can't work because it's a handsontable function in the initialization of the element. I edited for you to see that I can't use that event :/ – Erlaunis Sep 03 '15 at 13:22

2 Answers2

0

This appears to be a very basic question in JavaScript. I suggest you googling "load event js", "Javascript executes after page load", etc.

Unless you are looking for a specific way of doing it in handsontable, in which case it probably has to do with their hooks. For more information, look it up in the documentation.

Archy Will He 何魏奇
  • 9,589
  • 4
  • 34
  • 50
0

If what you want to do is change the cells definition after the page is loaded, you could always update it using

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

You could trigger this inside

$(docuemnt).ready(function(){ // updateSettings });
ZekeDroid
  • 7,089
  • 5
  • 33
  • 59