Get column settings

Tags: #<Tag:0x00007f0aff6bb3e8>

Hi,

We have an instance whereby we’d like to know if a column we are accessing has a particular ‘type’ or key/value pair assigned to it.

However, all we seem to be able to get is the column index - we can’t get the column settings that we provide in the columns: [] when creating a new Handsontable instance, nor can we find a function called getColumn or similar.

var hot = new Handsontable(el, {
   ...
   "columns":[
         {"name":"Ident","data":"ident","type":"hbr-cell"},
         {"name":"Title","data":"title","type":"hbr-truncated", "truncateLength":20}, 
    ]
    ...
);

Handsontable.cellTypes.registerCellType('hbr-truncated', {
    renderer: function(instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.HtmlRenderer.apply(this, arguments);
        if (instance.getDataAtCell(row, col).length > 30) {
            td.innerHTML = '<div title="' + td.innerHTML + '">' + td.innerHTML.slice(0, 30) + '...</div>';
        }
    },
    readOnly: true
});

(Where ‘30’ would be the truncateLength on the associated cells column)

In this instance (using a custom cell type with a custom renderer) we know the column index is 1, we wish to use that information to determine what the truncateLength is, so that in our renderer we can truncate the length of the text accordingly.

If this isn’t possible, is there a way to provide our truncate length (or any other custom variable for that matter) per column? This data has to be passed through at the instantiation of the Handsontable.

Hey @accounts1

if you work on a renderer you have access to instance, td, row, col, prop, value, cellProperties so you can

  1. get the TD element by calling
    instance.getCell(row, col) or for objects instance.getCell(row, instance.propToCol(prop))

  2. Get cell metadata
    instance.getCellMeta(row, col) or instance.getCellMeta(row, instance.propToCol(prop))
    and you’ll get a list of metadata like
    let type = instance.getCellMeta(row, col).type

Thanks for your reply, that works great! :slight_smile:

Great! If you’d need anything else I’m here to help.