How to maintain background color when browser is refreshed

Tags: #<Tag:0x00007efc6044ded8>

I am setting some cells with background-color by using “afterOnCellMouseDown” hook but when I reload my browser background-color disappears. I need to maintain those settings properties of each cell no matter how many times I refresh my browser. How could I do that?

Thanks.

Hi @jelm48

This issue seems to be the same as Losing information discussed with @adrian.szymanski

Do you need anything than what is mentioned in that thread?

Hi @aleksandra_budnik
I am trying to implement React-redux in order to maintain background-color with no success, I already used “cells” hook inside “afterOnCellMouseDown” hook but when I refresh my browser background color disappears. I already tried to set background color by using setCellMeta but This hook does not work.
I don´t know what else I can do.

Thank you.

Could you share the code that you use?

            .handsontable .colorDeRelleno{
          background-color: 'blue';
        }  

        const hot = useRef(null)
        afterOnCellMouseDown={function (event, coords, TD) {
                      ...
             hot.current.hotInstance.setCellMeta(coords.row, coords.col,'className','colorDeRelleno') (not working)

        hot.current.hotInstance.getCell(coords.row, coords.col).style.backgroundColor = colorDeRelleno (it works)
...
        }

I need to set background-color when some cell is clicked.

Ok, I see what’s going on. The getCell() and style.background won’t work here. You need to call setCellMeta() method and attach a className.

Yes @aleksandra_budnik
I call setCellMeta method but it does not work.

    .handsontable .colorDeRelleno{
              background-color: 'blue';
            }  
`hot.current.hotInstance.setCellMeta(coords.row, coords.col,'className','colorDeRelleno')`

After setCellMeta() you also need to call render(). Did you do that?

Yes . I did. But it´s not working.

Could you alter this demo https://jsfiddle.net/8gnkf0yq/ so it uses your logic?

Yes. I will try this demo again.

Are the states deleted When The browser is refreshed?

Thank you.

Yes, this demo is a front-end example and it does not store anything to the localStorage.

Ok @aleksandra_budnik.
I need to maintain information of each user when logins.
Here is my project.

Storing (in any other way that localStorage) has to be done on the server.

Handsontable provides hooks to control user choices and events and offers comprehensive API. But we do not offer back-end solutions. In your case you’d need to store users preferences on the server and when they log in run updateSettings() /setSellMeta() on the table or create a table with their preferred settings.

Yes. You´re right.
Thank you.

You’re welcome.

I’m closing this thread as solved. However, feel free to open z new open or write to us at support@handsontable.com when needed.