Couple of questions about getting data

Tags: #<Tag:0x00007efc70570d28>

Hi,

This is my first message, so be gentle with me please.

I am trying to use handsontable, and it is awesome. But, I am having some troubles about it.

  • How can I get all columns’ widths?
  • I am getting all table data with hot.getData(), but I want to get cell’s background color, font size, font color, alignment, etc too. How can I do that? Can I do that?
  • I know hot.getCellsMeta() function, but this gives me couple of supported class names, that’s all.
  • Long story short, I want to save the table with all datas, col width, styles, etc. How can I do that?

Thank you all,
Y.

No one? :roll_eyes:

OK. :pleading_face:

Hey @yusuf

Here’s Aleksandra from Support.

Please find the answers below

  • How can I get all columns’ widths?
    You can call the Core getColWidth method. Here’s a demo https://jsfiddle.net/AMBudnik/r31u0jef/ It shows the values even if you resize the columns.
    As you can see there’s a need to create a loop for all cells.

  • I am getting all table data with hot.getData() , but I want to get cell’s background color, font size, font color, alignment, etc too. How can I do that? Can I do that?
    You have two options
    https://handsontable.com/docs/7.2.2/Core.html#getCellMeta (for a single cell)
    https://handsontable.com/docs/7.2.2/Core.html#getCellMetaAtRow (for a row)
    As you can see there’s a need to create a loop for all cells/rows.

  • I know hot.getCellsMeta() function, but this gives me couple of supported class names, that’s all.
    To get more than a class you should use the getCellMeta as the parent object that. Here’s an example https://jsfiddle.net/AMBudnik/bo2d084z/ Unfortunately, we do not have documentation for all the cell meta but most of them are just our options https://handsontable.com/docs/7.2.2/Options.html

  • Long story short, I want to save the table with all data, col width, styles, etc. How can I do that?
    This might be a challenge to make all these loops and keep the performance on a high level so I recommend using hooks. Each of the hooks is triggered by a different behavior so if you could share some scenarios I’ll be happy to help :slight_smile:

1 Like

Hey @aleksandra_budnik,

Thank you for your detailed answer. I’ll try them.

PS: I have only one scenario. Save the table with all properties. :smiley:

How those are changed

  • do you have buttons that allow users to attach background
  • is there a custom renderer that ads className when values change
  • are there any custom dropdown or context menu options

Here are my answers:

  • I have buttons to change cells’ font size, font color, background color, font weight and alignment.
  • Nope.
  • Yep.

You can just run getSelected() which checks what are the coordinates of the cell and then pass those + your custom settings to the array of changes.
In Handsontable we’re lacking a method to get every metadata at once to rebuild the table so creating a separate array might be the only way to get those settings back.

Your first reply gave me some ideas, so I am trying them now.

Thank you so much for your help. :slight_smile:

Great :slight_smile: If you’d want anything please fee free to open a new ticket.