Author Topic: Highlight cell contents on edit  (Read 3700 times)

twz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Highlight cell contents on edit
« on: May 08, 2014, 05:55:48 am »
When a cell is selected for editing, the cursor appears at the start of the text. If you want to replace the text you need to delete the current contents first.

I would like the current contents to be highlighted automatically, so I can just start typing to replace the contents.

I'm surprised there doesn't seem to be an option for this - and nobody seems to have mentioned it before - or am I missing something obvious?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Highlight cell contents on edit
« Reply #1 on: May 08, 2014, 07:18:44 pm »
selection of text in editor is inbuilt only in PRO using a simple parameter

however you can write your own method to do it.

$grid.on( "focus", "input,textarea,div[contenteditable=true]",  function(evt){
  //code here to select text of $(this)
});

http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse
« Last Edit: May 08, 2014, 07:23:43 pm by paramquery »

twz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Highlight cell contents on edit
« Reply #2 on: May 09, 2014, 07:43:11 am »
Thanks for your reply.

I struggled with this for a while, but got it working eventually. Note: I had to select the text of 'this', not '$(this)'

twz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Highlight cell contents on edit
« Reply #3 on: May 18, 2014, 05:31:17 am »
Just to clarify - the reason I needed 'this' and not '$(this)' is that the code I used from your link was pure Javascript - so it was expecting a DOM element, not a jQuery object.