Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit and Sort combination support for DataTable #878

Closed
crkives opened this issue May 8, 2019 · 5 comments
Closed

Edit and Sort combination support for DataTable #878

crkives opened this issue May 8, 2019 · 5 comments
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@crkives
Copy link

crkives commented May 8, 2019

I'm submitting a ...

[x ] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57

Codesandbox Case (Bug Reports)
https://codesandbox.io/s/ox0kn6o559

Current behavior
On datatable with a editable and sortable column, if you sort then edit a column the inserted values will skip validation and resort as you type.

Expected behavior
The resort to not occur until after editing and validation is complete.

Minimal reproduction of the problem with instructions
https://codesandbox.io/s/ox0kn6o559

Click the table header for "last year sale" in the sandbox example to sort it ascending. Afterwards, click to edit the first column ( should be Song brand row at 17%). Edit this to 99. Song brand row will now jump to the bottom and you will now be editing the Microsoft brand row. If validation is provided then validation will not execute either for the Song brand record.

  • React version:
    16.7.0

  • PrimeReact version:
    3.1.2

  • Browser: all

  • Language: all

@cagataycivici cagataycivici added the Type: Bug Issue contains a defect related to a specific component. label May 30, 2019
@ahmetcevahircinar
Copy link

I have same problem. Any fix or suggestion? Thank you.
Adsız

@NellyHaglund
Copy link
Contributor

Having the same problem. Any solution or fix yet? Thanks.

@mertsincan mertsincan self-assigned this Feb 9, 2021
@mertsincan mertsincan changed the title Sort while editing datatable bug Edit and Sort combination support for DataTable May 16, 2021
@mertsincan mertsincan added this to the 6.4.0 milestone May 16, 2021
mertsincan added a commit that referenced this issue May 16, 2021
@mertsincan
Copy link
Member

Hi,

Fixed for PrimeReact and PrimeVue. The DataTable component never stores the user's data. Therefore, in any state change, the sort and filter events are called again. That's why you can use onValueChange to send the data that changes during these events to the user. With this callback, you can sync the calculated data with the data you give to the DataTable. Exp;

const [products, setProducts] = useState([]);
const onValueChange = (value) => {
    setProducts(value);
}

...

<DataTable value={products} editMode="cell" onValueChange={onValueChange}>
   ...
</DataTable>

Best Regards,

@master117
Copy link
Contributor

master117 commented Jun 7, 2021

Won't this still make the sorting move while you type? Doesn't this lead to issues with pagination? Or is this only called after Changes are finished / onBlur is called?

@gaganjot07
Copy link

gaganjot07 commented Jul 22, 2021

I still have this issue on version 6.5.0 The grid is sorted and when I click on a cell to edit the rows are re-ordered. I tried the onValueChange example above, however it seems that the grid fires onValueChange only when the user clicks on the cell to edit it. Ideally the event should be fired as soon as the data passed to the grid in the 'value' prop is changed.
I prepared a small example of the issue here
https://codesandbox.io/s/frosty-galois-ripfy?file=/src/App.tsx
Click on the add button on the top of the grid then try to edit the quantity column cell, the rows will be re-ordered on the first edit. Afterwards on subsequent edits the grid corrects itself. So the problem is only on first edit.

This issue is a blocker for me, any help will be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

No branches or pull requests

7 participants