This is a migrated thread and some comments may be shown as answers.

Inline Edit Grid Cell Focus Is Not Working?

1 Answer 875 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
GokuJim
Top achievements
Rank 1
GokuJim asked on 21 Mar 2019, 01:52 PM

In another thread named: "", it was discussed how to set the focus to a grid cell in a KendoReact Grid control. Here's the example provided from that thread:

>>

"This can be done by selecting the desired element based on a query selector and calling its focus method:
      https://stackblitz.com/edit/react-lthy76?file=app/main.js"

<<

That's a pretty good example, however in real UX it doesn't work that way....

Under a normal use case for UX, you would not want the user to have to press a button such as "Focus Input" or "Focus Textbox" prior to then selecting an inline Edit button. What users would more likely want to see is when they press the inline grid Edit button that the focus immediately appears on the particular column that starts the editing.

Thus, in my use case, I have a single editable textfield inside a Grid, and using the code from the example in stackblitz above,

i.e. >>

    let firstInput = document.getElementsByClassName('k-textbox')[0];

    if (firstInput) {

      firstInput.focus();
   }

<<

inside an enterEdit(dataItem) function called from an Edit command cell (from code grabbed from the KendoReact Grid documentation)

the result is that firstInput is always "undefined" and focus is never given to that cell.

BTW, Here's the full enterEdit() routine:

enterEdit = (dataItem) => {
   this.setState({
     originalItem: dataItem
   });
   this.updateGridData(this.state.data, dataItem).inEdit = true;
   this.setState({
     data: this.state.data.slice()
  });
  let field = document.getElementsByClassName('k-textbox')[0];
  if (field) {
    field.focus();
  }
};

Is there a reason why the field is always "undefined"? Could this be a timing issue? Does the focus need to be preset prior to a call for editing?

Can anyone shed some light on this issue?

Thanks,

Jim Minnihan

SKF, Inc.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 22 Mar 2019, 08:03 AM
Hello, James,

Thank you for the example and the code.

Indeed this is not a real-world example, I made it with buttons for better demonstration the code that has to be executed.

As for executing this focus inside the enterEdit function: the issue is indeed a timing one. Once this function is called, the Grid is still not in edit and not editors are shown.

I can suggest using a flag and a componentDidUpdate lifecycle method:

https://stackblitz.com/edit/react-lthy76-mdskrz?file=app/main.js

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
GokuJim
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or