EasyUI Forum
April 29, 2024, 08:55:27 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Issue with datagrid endEdit method  (Read 15765 times)
r2ferna
Newbie
*
Posts: 21


View Profile
« on: October 30, 2013, 09:28:25 AM »

Hi Srs:

I'm using an in-line edit datagrid.
When all changes are made, I'm trying to get the datagrid changed rows with next function:

  function aceptaCambios() {
      // var rowsCh = $('#dgP').datagrid('getChanges');
      // console.log(rowsCh.length, rowsCh);
      var rowsChanged = [];
      var originalRows = $('#dgP').datagrid('getData').orgRows;
      console.log(originalRows[3]['p-vp']);
      var rows = $('#dgP').datagrid('getRows');
      $.each(rows, function(indx,row) {
          var rowChanged = false;
          var orgRow = originalRows[indx];
          console.log(row['p-vp'], orgRow['p-vp'], row['p-gp'], orgRow['p-gp']); 
          if (row['p-vp'] != orgRow['p-vp']) rowChanged = true;
          if (row['p-gp'] != orgRow['p-gp']) rowChanged = true;
          if (rowChanged) rowsChanged.push(row);
      });
      console.log(rowsChanged.length, rowsChanged);
      // $('#dgP').datagrid('acceptChanges');
  }     

The issue is: The field values of row are equal to values in orgRow data (original rows) so rowChanged variable never becomes true.

The originalRows data are copied at end of the loadFilter function of datagrid.

function grid_loadFilter(data) {
    ...
    ...
      if (this.id == "dgP" && !data.orgRows) {
         data.orgRows = data.rows;
         console.log('loadData row = 3', data.orgRows[3]['p-vp']);   // tracking
      } 
      return data;
}

After tracking the issue, I found the datagrid 'endEdit' method seems to be the culprit.

function cambiaRow(indx){
      var originalRow = $('#dgP').datagrid('getData').orgRows[indx];
      console.log('cambiaRow Start: row =', indx, originalRow['p-vp']);         

      $('#dgP').datagrid('beginEdit', indx);
      $('#dgP').datagrid('selectRow', indx);

      originalRow = $('#dgP').datagrid('getData').orgRows[indx];
      console.log('cambiaRow End: row =', indx, originalRow['p-vp']);         
  }
 
  function aceptaRow(indx){
      var originalRow = $('#dgP').datagrid('getData').orgRows[indx];
      console.log('aceptaRow Start: row =', indx, originalRow['p-vp']);         

      $('#dgP').datagrid('endEdit', indx);
      $('#dgP').datagrid('selectRow', indx);   

      originalRow = $('#dgP').datagrid('getData').orgRows[indx];
      console.log('aceptaRow End: row =', indx, originalRow['p-vp']);         
  }
 
This are the console tracking messages: (I'm tracking the original data for updated row = 3)
loadData row = 3 No                w-usr-grp.html# (línea 269)
cambiaRow Start: row = 3 No        w-usr-grp.html# (línea 294)
cambiaRow End: row = 3 No          w-usr-grp.html# (línea 298)
aceptaRow Start: row = 3 No        w-usr-grp.html# (línea 306)
aceptaRow End: row = 3 Si          w-usr-grp.html# (línea 310)

As You can see, After "endEdit" method, not only the data.rows are changed, the original-data copy is changed too!!
Is this a issue or am I loosing something?

I tried copying the original data to a JavaScript variable out-of the datagrid data and the same behaviour is shown.
 
Please can you help me?

MTIA
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: October 31, 2013, 12:48:21 AM »

Why don't use 'getChanges' method to get changed rows? Please try this:
Code:
var rowsCh = $('#dgP').datagrid('getChanges');
console.log(rowsCh);
Logged
r2ferna
Newbie
*
Posts: 21


View Profile
« Reply #2 on: October 31, 2013, 12:03:05 PM »

Thanks for your help!

Because the rows in datagrid can be changed many times before they are send to server.
Example:
a row (r) has a field 'f1' with value 'xyz'. It's changed so the new value is '123'.
After changing other rows, I change my mind and change again the row (r) so now, the "new" value is 'xyz'.
the datagrid('getChanges') counts the row (r) as changed but it doesn't changed really.
I want to send to server only the rows really changed.
To solve it, I figured out make a "picture" of the original rows and check against it.

Now, ooopsss!!!, I found javascript copies objects and arrays as a kind of "by reference",
so the copy of data.rows
Code:
data.orgRows = data.rows;
was not a real/self-contained copy.

So, I had to use this line of code to make two different objects:
Code:
data.orgRows = $.extend(true, {}, data.rows);
and everything is working ok .... until now!!  Smiley Smiley

Thanks again and so long!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!