Clear JSON datatable when user removes cell data

Posted by: adisa.craig on 4 February 2021, 6:03 am EST

    • Post Options:
    • Link

    Posted 4 February 2021, 6:03 am EST

    Is there a way for me to clear the corresponding datatable value whenever a user removes cell content and the cell is using the default styles?

  • Posted 4 February 2021, 10:39 pm EST

    Hi Adisa,

    If I understand correctly you want to reflect the changes in JSON whenever the user changes the data on the sheet. For this, you may use sheet level data binding. Please refer to the following code snippet and attached sample that demonstrates the same.

    Further, if it is not the case please explaining more about the use case so that we could have a better understanding of the issue and help you accordingly.

    Regards

    
        var customers = [
           { ID:0, Name:'A', Info1:'Info0' },
           { ID:1, Name:'B', Info1:'Info1' },
           { ID:2, Name:'C', Info1:'Info2' },
        ];
        sheet.autoGenerateColumns = true;
        sheet.setDataSource(customers);
       //if the user changes the data it will refrecl in customers array since it is a two way binding
    
    

    sample: https://codesandbox.io/s/cool-water-00gfz?file=/src/index.js

    DataBinding Demo: https://www.grapecity.com/spreadjs/demos/features/data-binding/sheet-level-binding/purejs

    Regards

    Avinash

  • Posted 9 February 2021, 5:21 am EST

    Hi Avinash,

    no I am not referring to when data is binded. for example if the spread is initialized similarly to this https://www.grapecity.com/spreadjs/demos/features/cells/hyperlink/hyperlink-formula/purejs where an empty spread is initialized and then data is added by the user. If as in this example the user added content to the first 10 rows and first column, the JSON relflects it correctly within the datatable key. If the user then removes data from the last 5 rows, the datatable JSON still shows all 10 rows and only the value key is removed from the last 5 rows it still contains a style key.

    Is there a way to clear this style key so that the datatable only reflects the cells with values in them

  • Posted 9 February 2021, 11:15 pm EST - Updated 3 October 2022, 12:58 am EST

    Hi Adisa,

    We are unable to replicate the issue at our end. Could you please refer to the following gif of our observation and let us know if we have missed any steps. YOu may las check the following sample that we used for testing and modify it to replicate the issue.

    sample: https://codesandbox.io/s/trusting-kowalevski-m3qq9

    Regards

    Avinash

  • Posted 10 February 2021, 9:13 am EST

    Hi Avinash, the easiest way to reproduce my issue in the sandbox that you provided is to carry out the following steps.

    • Remove lines 7-14 (remove all styles)

    • in cell 0,0 type any number

    • drag fill from cell 0,0 to cell 1,1

      click the getdatatable button (cell 0,0 will have only a value but all other cells will have a value and style key

    • remove content from cell 1,1

      click the getdatatable button (cell 1,1 will only have a style key)

  • Posted 10 February 2021, 8:20 pm EST - Updated 3 October 2022, 12:58 am EST

    Hi Adisa,

    This is the expected behavior from SJS. When we drag fill the range all the style gets copied to the Cell. You could confirm that by filling the range with “fill without formatting” and you will see that style is not adding to the datable.

    Also if we clear the content of the Cell the style is not cleared. For clearing the Style you need to set the style of that cell to null. Please refer to the following gif and attached sample and let us know if you face any issues.

    sample: https://codesandbox.io/s/amazing-varahamihira-un58u

    Regards

    Avinash

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels