Dropdown w/ create new option

Posted by: ryan on 24 August 2021, 5:46 pm EST

    • Post Options:
    • Link

    Posted 24 August 2021, 5:46 pm EST

    How would I add a dropdown to a cell in SpreadJS that enables me to create a new option? Like this: https://react-select.com/creatable

  • Posted 25 August 2021, 2:05 am EST

    Hi,

    As the default behavior, validator dropdowns do not allow adding new elements, however to achieve the required functionality you may handle the ValidationError event and add the current value to the list of validator if it is a new value.

    You may refer to the following code snippet and the sample demonstrating the same:

    spread.bind(GC.Spread.Sheets.Events.ValidationError, function (e, args) {
          // if list validator, add the current value to list
          if (
            args.validator.type() ===
            GC.Spread.Sheets.DataValidation.CriteriaType.list
          ) {
            // update values
            let existingListValues = args.validator.condition().expected();
            let cellType = args.sheet.getCellType(args.row, args.col);
            let curEditValue = cellType.getEditorValue(
              cellType.getEditingElement()
            );
    
            args.validator
              .condition()
              .expected(existingListValues + "," + curEditValue);
          }
        });
    

    https://codesandbox.io/s/cocky-danny-6ee9c?file=/src/index.js

    ~sharad

Need extra support?

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

Learn More

Forum Channels