Search code examples
javascriptformattinghandsontable

Handsontable: Update column setting, but exclude the first row


We have an operation in our Hands on table app that assigns a format to columns via a drop down as demonstrated here: http://docs.handsontable.com/0.16.1/demo-custom-renderers.html#page-dropdown

When a new format is picked, we apply the formatting to the column.

columns[i].type = type;
instance.updateSettings({columns: columns});

What I need to do is exclude the first row from this type of column update as it is a static text field which should not be changed. Is there an example of this available?


Solution

  • According to the documentation, the cells option takes precedence over columns. So what you could do is set cells to the following:

    cells: function(row, col, prop) {
        var cellProperties;
    
        if (row === 0) {
            cellProperties = {
                type: 'text' // force text type for first row
            };
    
            return cellProperties;
        }
    }
    

    What this will do is set a type to the first row. Now when you update columns, it won't apply to the first row because cells is taking precedence.