Customizing Context Menu and Retrieving Selected Range in SpreadJS Designer?

Posted by: nguyenvu.work on 3 August 2023, 7:04 am EST

    • Post Options:
    • Link

    Posted 3 August 2023, 7:04 am EST - Updated 11 January 2024, 2:40 pm EST

    In my current project, I am working on customizing a context menu that will display a RangeSelect dialog. My objective is to retrieve the value from the InputField after the user clicks the Ok button. I am following the documentation provided at:

    https://www.grapecity.com/spreadjs/docs/spreadjs_designer_component/customizations/add_new_dialog
    .

    Specifically, I aim to display this menu when a user clicks on a cell. From what I understand, this behavior is determined by the

    visibleContext
    prop. However, I’m unsure about how to determine whether its value is
    ClickRowHeader
    or something else. (It was defined only as a
    String
    )

    Although I have managed to display the dialog, I am facing an issue in the

    successCallback
    function where I cannot access the selected range that I have chosen. How can I retrieve this information?

    When I explore the TypeScript definitions for more information, I encounter a function signature like this:

    function showDialog(templateName: string,  bindingData: Object,  successCallback: Function,  errCallback?: Function,  validCallback?: Function,  popupElement?: HTMLElement): void;

    I would like to understand the purpose of the

    Object
    and
    Function
    arguments in this context. How can I access further documentation to gain a better understanding?

  • Posted 4 August 2023, 1:54 am EST - Updated 4 August 2023, 1:59 am EST

    Hi,

    Yes, the visibleContext takes string as value. There are many options available for the visibleContext. For example, options are “ClickRowHeader” , “ClickColHeader” , “ClickViewport”, “ClickCorner”, “TabStripSelected”.

    You could set the visibleContext based on if you want to show the option on rowHeader, colHeader, viewportCell, cornerCell, tabStrip, etc. You could add the options seperated by OR(" || ") operator.

    For example, if you want to show the context menu on rowheader, colHeader and tab strip, you could use the following option:

    visibleContext: "ClickRowHeader || ClickColHeader || TabStripSelected",

    You could follow the mentioned steps to register and get the values for inputs in the Designer’s Dialog.

    1. When defining the template for the Dialog, add binding properties for input elements. For example, in the example, binding property “textProp” is being added to the “TextEditor” and binding property “rangeProp” is being added to the “RangeSelect”.
    ....
    {
        type: "Column",
            children: [
                {
                    type: "TextEditor",
                    margin: "0 0 0 10px",
                    // Set the Binding Path for Text Editor
                    bindingPath: "textProp"
                }
            ]
    }
    .....
    {
        type: "RangeSelect",
            title: "Select Range",
                absoluteReference: true,
                    needSheetName: false,
                        margin: "5px -5px",
                            // Set the binding Path for RangeSelect
                            bindingPath: "rangeProp"
    }
    ....
    1. Pass the object as the second parameter in the showDialog() method. This object will bind to the binding properties defined inside the template. You could also pass the initial values to bind to the input elements.

    For example, in the following example, the object has two properties that binds with the binding properties defined in the template. Also, the text editor has been given initial value.

    ....
    // Pass the Binding object. You may also pass the initial values
    let dialogOptions = {
        textProp: "InitialValue",
        rangeProp: ""
    };
    ....
    1. You will get the values in the successCallBack function by the property name defined earlier.

    For example, you could refer to the following code snippet:

    ....
    // Get the Result Value
    console.log("Text: " + result.textProp);
    console.log("Range: " + result.rangeProp);
    ....

    I hope you get clarification on getting the value of the range select. You could refer to the following showDialog method that shows an example on getting the values.

    We are constantly adding more documentation about the Designer Components and the missing details will be added in the future. We are sorry for any inconvenience it may have caused.

    Please let us know if you still face any issues or have doubts.

    Sample: https://jscodemine.grapecity.com/share/hOrYCXFmA0uptYwb1G0AJQ/?IsEmbed=false&Theme=Unset&PreviewDirection=0&IsEditorShow=true&IsExplorerShow=true&IsPreviewShow=true&IsConsoleShow=true&IsRunBTNShow=false&IsResetBTNShow=false&IsOpenInCodemineBTNShow=false&PanelWidth=20&PanelWidth=50&PanelWidth=30&defaultOpen={"OpenedFileName"%3A["%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    References:

    showDialog method: https://www.grapecity.com/spreadjs/api/v15/designer/modules/GC.Spread.Sheets.Designer#showdialog

    setConfig method: https://www.grapecity.com/spreadjs/api/designer/classes/GC.Spread.Sheets.Designer.Designer#setconfig

    registerTemplate method: https://www.grapecity.com/spreadjs/api/v15/designer/modules/GC.Spread.Sheets.Designer#registertemplate

    Regards,

    Ankit

  • Posted 4 August 2023, 3:02 am EST

    Thank you for your support. Although there are some missing details in the documentation and I sometimes encounter inconveniences, what truly satisfies me is your prompt and continuous support. Thank you once again.

  • Posted 4 August 2023, 6:51 am EST

    Hi,

    You’re welcome! We’re grateful for your feedback. While we recognize that there might be certain details missing from our documentation and you’ve faced some inconveniences, we’re glad that our consistent and timely support has left a positive impression on you.

    Should you encounter any challenges or require additional help, please feel free to get in touch.

    Regards,

    Ankit

Need extra support?

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

Learn More

Forum Channels