Caret Position

Posted by: grapecity on 31 October 2017, 12:38 am EST

    • Post Options:
    • Link

    Posted 31 October 2017, 12:38 am EST

    I know that to set cell focus, flex.select(new wjGrid.CellRange(row, col, row, col), true) will do. However, if I need to set the caret position to the end of the string, how can I do it. For example, cell (row 4, col 5) contains the string ‘Test’. If I set focus flex.select(new wjGrid.CellRange(4, 5, 4, 5), true) and type ‘i’, string ‘Test’ is replacing with ‘i’ instead of let me type ‘Testing’ if caret is positon at the end of ‘Test’. Thank you very much.

  • Posted 31 October 2017, 4:23 pm EST

    Hi Hoang,

    For this, you need to handle beginningEdit event of FlexGrid and need to set input value to the new value.

    For your reference, please refer to the attached sample for the same.

    ~Manish

    FlexGrid_caretPosition.zip

  • Posted 1 November 2017, 8:22 am EST

    Thank you sir very much

  • Posted 2 November 2017, 1:49 am EST

    Hi Manish,

    Sorry for my confusion question. Let me rephrase it:

    I am looking for a method to set the blinking cursor at he end of the text in a cell. I am checking your code example:

    flex.beginningEdit.addHandler(function(s,e){

    var _cellData= s.getCellData(e.row,e.col,true);

    setTimeout(function(){

    var _txt=s.activeEditor.value;

    if(_cellData!==_txt){

    s.activeEditor.value=_cellData+_txt;

    }

    },7);

    });

    I have tried it and the blinking cursor is not showing when a cell in SelectionChanging. I have looked into Flexgrid Class document and found out that setSelectionRange (http://demos.wijmo.com/5/Angular/WijmoHelp/WijmoHelp/topic/wijmo.Module.html#setSelectionRange) may be the one I am looking for but I do not know how to call it inide selectionChanging event.

    setSelectionRange(e: HTMLInputElement, start: number, end?: number): void

    start and end will be the length of cellText. e: HTMLInputElement is what I do not know how to retrieve it to pass into setSelectionRange.

    Do you have another method of doing this sir?

  • Posted 2 November 2017, 4:21 pm EST

    Hi Hoang,

    For this, you need to handle selectionChanged event instead of beginningEdit event. Please refer to the following code snippet:

    flex.selectionChanged.addHandler(function(s,e){   
    		// timeout for set caret position to last in Input on selection change using mouse 
                    setTimeout(function(){
                        var _cellData= s.getCellData(e.row,e.col,true);                       
                        if(s.columns[e.col].dataType!==wijmo.DataType.Boolean){
    			// start editing to activate editing in FlexGrid
                            s.startEditing(true,e.row,e.col,true);
                            wijmo.setSelectionRange(s.activeEditor,_cellData.length)
                        }
                    });
    

    Hope it helps!

    ~Manish

Need extra support?

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

Learn More

Forum Channels