Setting the value of dropdowns with javascript

Posted by: keith.emanuel on 28 February 2019, 4:53 pm EST

    • Post Options:
    • Link

    Posted 28 February 2019, 4:53 pm EST

    Hello,

    It seems like there is sample code on how to set cell values using javascript, and it works for plaintext and checkboxes just fine. However, I haven’t been able to set the value of a select dropdown through javascript, unless I modify it manually through the UI first.

    Is there any sample code on how to do this using SpreadJS 10?

    I’ve tried many combinations of

    sheet.setActiveCell

    sheet.startEdit

    sheet.getCell.value

    sheet.getCell.text

    sheet.setValue

    but I always have to change the value using the UI first, then I can just call the set methods directly.

    Also, is there a function that returns a boolean describing whether a cell is editable through the UI?

    Thanks!

  • Posted 1 March 2019, 9:40 am EST

    Hello,

    I am having no trouble setting the value for a combobox cell. I used the code as follows:

    
      $(document).ready(function () {
                var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
                var activeSheet = spread.getActiveSheet();
    
                var cellType2 = new GC.Spread.Sheets.CellTypes.ComboBox();
                cellType2.items(["a", "b", "c"]);
                activeSheet.getCell(2, 2).cellType(cellType2);
                       
                $("#btnChangeComboval").click(function () {
                    activeSheet.setValue(2, 2, "b");
    
                });
            });
    
    

    Please refer to the attached sample application.

    Thanks,

    Deepak SharmaSpreadJSSetCombo.zip

  • Posted 5 March 2019, 12:00 pm EST

    Hey Deepak, thanks again for the response.

    Unfortunately, this still won’t change the value unless I modify it through the UI first. Any idea why that would be? I’m also pulling spreadsheet from the page using findControl, not creating a new one.

    Also, is there any way to check whether a cell is editable through the UI?

  • Posted 5 March 2019, 5:55 pm EST

    It actually looks like there is a formula on the cell that is removed when changing the value manually. Is there a way to clear the formula through JS?

  • Posted 6 March 2019, 1:10 am EST

    Hello,

    Yes, you can simply use set the formula to null or clear the cell/cellrange:

    activeSheet.setFormula(1,1," ",GC.Spread.Sheets.SheetArea.viewport);

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels