EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: officecode on December 01, 2018, 10:51:56 PM



Title: The rows that have been deleted in the datagrid, how to restore them again?
Post by: officecode on December 01, 2018, 10:51:56 PM
I tried multiple methods like loadData and it won't work.
Please help, thank you!

Code:

var rows = $('#test').datagrid('getChanges','deleted');
//How to restore them again?



Title: Re: The rows that have been deleted in the datagrid, how to restore them again?
Post by: officecode on December 02, 2018, 07:09:34 PM
I tried using the code below, but there is no way to reload only on the current page:

Code:
var dt = $('#test').datagrid('getRows');
var delrows = $('#test').datagrid('getChanges','deleted');
$('#test').datagrid('loadData',dt.concat(delrows));


Title: Re: The rows that have been deleted in the datagrid, how to restore them again?
Post by: stworthy on December 02, 2018, 07:24:09 PM
After calling the 'deleteRow' method to delete a row, you can call 'rejectChanges' method to restore the data. If the 'acceptChanges' method is called, you will lost the deleted rows.


Title: Re: The rows that have been deleted in the datagrid, how to restore them again?
Post by: officecode on December 02, 2018, 10:03:16 PM
After calling the 'deleteRow' method to delete a row, you can call 'rejectChanges' method to restore the data. If the 'acceptChanges' method is called, you will lost the deleted rows.

I know the usage of 'rejectChanges', but after the execution, all the changes will be lost.
Sometimes, I may just want to recover deleted rows.
If the method 'loadData' can add  a page parameter, it would be great!
thank you for your help!


Title: Re: The rows that have been deleted in the datagrid, how to restore them again?
Post by: stworthy on December 02, 2018, 11:54:35 PM
If you can get the deleted rows, please call 'appendRow' or 'insertRow' method to insert them.
Code:
var dg = $('#dg');
var deletedRows = dg.datagrid('getChanges','deleted');
for(var i=0; i<deletedRows.length; i++){
  dg.datagrid('appendRow', deletedRows[i])
}
dg.datagrid('acceptChanges')


Title: Re: The rows that have been deleted in the datagrid, how to restore them again?
Post by: officecode on December 03, 2018, 02:07:05 AM
Haha, why didn't I think of using appendRow? This method is very good, although it may not be the original location after the addition.
Thank you very much, EasyUI is great, the administrator is better.