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

Delay Editable Grid Sorting Until Inline Edit Completion/Save

1 Answer 268 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
GokuJim
Top achievements
Rank 1
GokuJim asked on 08 Aug 2019, 05:35 PM

How can I delay the sorting feature of an editable Kendo React Grid until the user has completed and saved the inline edit of a sortable column field?

 

Thanks,

Jim

SKF USA, Inc.

1 Answer, 1 is accepted

Sort by
0
Kiril
Telerik team
answered on 12 Aug 2019, 07:28 AM
Hello James,

The described behavior can be achieved by setting a state variable to 'true'/'valse' and prevent the onSortChange event based on that variable. For example we can have an 'inEdit' variable which is set to true every time the cell/row enters in an edit mode, and set it to 'false' every time the user cancel/confirm the changes.

In the onSortChange event we can check if the variable is true and do not update the sort descriptor, or if it's false we can proceed the handling as normal.

I've prepared the following stackblitz example, demonstrating the usage of both Inline editing and Sorting features of the KendoReact Grid component:
https://stackblitz.com/edit/react-dsufbx?file=app/main.jsx
Please check my comments in the code for the logic responsible for the described behavior.

Please let me know if you need further assistance, or if i misunderstood your use case and i'll be more than happy to help!

Regards,
Kiril
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
Tony
Top achievements
Rank 1
commented on 01 Nov 2021, 09:44 PM | edited

I am having the same issue.  The provided answer does not appear to be working correctly.  When using the solution add a new record and type in "z" and the new row with jump to a different position.  The same will occur when editing an existing row.

Tony

Filip
Telerik team
commented on 02 Nov 2021, 02:03 PM

Hello, Tony,

The following behavior occurs because we are implementing the sorting logic in the data prop of the Grid, thus sorting every time on render. The grid operates with the data that we provide and if we want to change a certain behavior it is best to implement our desired logic to the data itself. In this case, we can perform the sorting in the handleSortChange event. This will apply the sorting only when the user sorts again:

handleSortChange = (e) => {
    // Prevent Sort change if any row is in edit mode!
    if(this.state.inEdit) {return;}
    this.setState({
      data: orderBy(this.state.data, e.sort),
      sort: e.sort
    });
  }

You can also review the full code and functionality in the following runnable snippet:

https://stackblitz.com/edit/react-dsufbx-bwydnf?file=app/main.jsx

Kind Regards,

Filip

 

Tags
General Discussions
Asked by
GokuJim
Top achievements
Rank 1
Answers by
Kiril
Telerik team
Share this question
or