Setvalue method is not working

Posted by: honhatan58 on 15 August 2022, 6:44 am EST

    • Post Options:
    • Link

    Posted 15 August 2022, 6:44 am EST

    Hi team,

    this is my code

    sheet.bind(GC.Spread.Sheets.Events.EditChange, function (sender, args) {

    let { sheet, row, col, editingText} = args

    sheet.setValue(row, col, “12.00”, GC.Spread.Sheets.SheetArea.viewport)

    })

    i want to update value of the cell when user typing. But my code do not work. Could you provide me some solution for that.

    Thank you so much.

  • Posted 16 August 2022, 3:02 am EST

    Hi team,

    I saw, after i set value, the value of the cell has been changed, but UI do not re-render.

    I call spread.refesh() in this method. but it isn’t resolved this problem.

  • Posted 16 August 2022, 3:19 am EST

    Hi,

    “EditChange” Event is trigged when the cell is in edit mode and the text is changed. When you are setting the value of the cell using the setValue() method, it does change the value of the cell. You can verify it by logging the value of the cell:

    sheet.bind(GC.Spread.Sheets.Events.EditChange, function (sender, args) {
    let { sheet, row, col, editingText } = args;
    sheet.setValue(row, col, "12.00", GC.Spread.Sheets.SheetArea.viewport);
    console.log(sheet.getValue(row, col));
    });
    

    However, when the editing of the cell is complete, the cell value will the text that is inside the editing element. You can set the value of the cell after the editing of the cell ended by using the EditEnded Event.

    sheet.bind(GC.Spread.Sheets.Events.EditEnded, function (sender, args) {
    console.log("Edit Ended");
    sheet.setValue(args.row, args.col, "12.00", GC.Spread.Sheets.SheetArea.viewport);
    });
    

    Sample: https://jscodemine.grapecity.com/share/P-rNDCGu3Eigf4Gben7dpw/

    API Reference(s):

    EditEnded Event: https://www.grapecity.com/spreadjs/docs/latest/online/SpreadJS~GC.Spread.Sheets.Events~EditEnded_EV.html

    Regards

    Ankit

  • Posted 16 August 2022, 3:41 am EST

    Hi,

    Because the event EditEnded just call when leaved a cell, but i want to handle while user typing in cell,

    for example, i do not allow the user input alphabet character and show it in a cell but user still input another character

  • Posted 17 August 2022, 3:32 am EST

    Hi,

    As per my understanding, you don’t want the user to input alphabet characters, but the user can enter other characters. If this is the use case, you can use the activateEditor method to get the editorContext, add the keydown listener and prevent the default behavior.

    For example, you can refer to the following sample that I have created for you: https://jscodemine.grapecity.com/share/nDwEQfyRAU6xMEfWp4RPoQ/

    API References:

    activateEditor method: https://www.grapecity.com/spreadjs/docs/latest/online/SpreadJS~GC.Spread.Sheets.CellTypes.Base~activateEditor.html

    CellTypes type: https://www.grapecity.com/spreadjs/docs/latest/online/SpreadJS~GC.Spread.Sheets.CellTypes.html

    Please let us know if you have a different use case.

    Regards

    Ankit

  • Posted 17 August 2022, 4:30 am EST

    Hi admin,

    Thank you so much for you answer,

    I have another case. I allow user input follow format of decimal(18,2). Could you please give me way. I find the formatter method but it is display when user leaved

  • Posted 17 August 2022, 11:11 am EST - Updated 3 October 2022, 9:06 am EST

    Hi team,

    I think your solution can’t cover all case, i test and get result as below. Another case has problem when i can’t paste number value into the cell



    When i paste value into the cell (do not double click before). The event ClipboardPasting can work. But I double click to cell and paste value, this event can’t not work

  • Posted 19 August 2022, 7:57 am EST

    Hi.

    I have another case. I allow user input to follow the format of decimal(18,2). Could you please give me away?

    For this, you need to implement your own parser and parse the keys that have been pressed inside editmode (in keydown event handler) accordingly.

    For this you need to handle paste on the editor element. Please refer to the following code snippet and attached sample that explains the same.

            editorContext.addEventListener("keydown", function (event) {
                // Check for alphabets 
    
                if (!event.ctrlKey &&  //for allowing ctr action such as paste
                event.keyCode >= 65 && event.keyCode <= 90 ||  //for alphabets
                (event.target.innerText.includes(".") && event.key =="."))  { // for . validation
                    event.preventDefault();
                }
            });
            editorContext.addEventListener("paste", function (event) {
                // add validation on clipboard text that is going to be pasted
                var text = parseInt(event.clipboardData.getData('text/plain'))
                if (isNaN(text)) {
                    event.preventDefault();
                    event.stopImmediatePropagation();
                }
            });
    

    sample: https://jscodemine.grapecity.com/share/L8FxxM5rIEC5bRhph6Bckg/

    Regards,

    Avinash

  • Posted 21 August 2022, 4:38 am EST

    Hi team,

    Thank you so much for you answer.

    I got it,

    sincerely

Need extra support?

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

Learn More

Forum Channels