EasyUI Forum

General Category => General Discussion => Topic started by: Rimokas on August 26, 2015, 01:26:11 AM



Title: datagrid-cellediting - how trully to update cell
Post by: Rimokas on August 26, 2015, 01:26:11 AM
Hi,

Problem with cell editing, datagrid-cellediting plugin. After editing cell, cell background became blue . Trying to put chars in filter box, in open again editor in just edited cell and chars goes here ...

I'm trying with remote database and datagrid is with 3 plugins :

Code:
  <script src="jeasy/jquery.min.js"></script>
   <script src="jeasy/jquery.easyui.min.js"></script>
   <script src="jeasy/datagrid-filter.js"></script>
   <script src="jeasy/datagrid-scrollview.js"></script>
   <script src="jeasy/datagrid-cellediting.js"></scrip>
   <script id="script-lang" src="jeasy/locale/easyui-lang-lt.js"></script>
<script src="jsf/func.js"></script>
   <script src="jsf/grd.js"></script>

I'm using only 'onAfterEditing' event :

Code:

      this.create_grid = function() // "this" here - created own object storing info about grid columns and own parameters ...
      {
         var obj = this;
         var ret =
         {   
            fit        : true,
            idField    : this.pagr_rakt,
            columns    : [ this.grid_stulp ],
            toolbar    : [
            {
               id     : 'naujas',
               text   : 'Naujas',
               iconCls: "icon-add",
               plain  : true,
               handler: function(){ $.messager.alert( "naujas" ); } //$( '#dg' ).datagrid( 'addRow' ) }
            },
            {
               id     : 'salint',
               text   : 'Šalinti',
               iconCls: "icon-remove",
               plain  : true,
               handler: function(){ $.messager.alert( "salinti" ); }
            },
            {
               id     : 'saugot',
               text   : 'Išsaugoti',
               iconCls: "icon-save",
               plain  : true,
               handler: function(){ $.messager.alert( "issaugoti" ); }
            },
            {
               id     : 'atmesti',
               text   : 'Atmesti',
               iconCls: "icon-undo",
               plain  : true,
               handler: function(){ $.messager.alert( "atmesti" ); }
            }],
            view          : scrollview,
            striped       : true,
            pagination    : false,
            pageSize      : this.pusl_dyd,
            singleSelect  : false,
            autoRowHeight : false,
            remoteFilter  : true,
            remoteSort    : true,
            multiSort     : true,
            clickToEdit   : false,
            dblclickToEdit: true ,
            url           : format_url( this, "get" ),
            onAfterEdit   : function( index, row, changes )
            {
                cell_update( index, row, changes, obj, this );
            }
         }   
         return ret;
      }

function cell_update:

Code:
function cell_update( index, row, changes, obj, dg )
{
   var laukai = Object.keys( changes );
   var laukas = laukai[ 0 ];
   var reiksm = changes[ laukas ];
   var snd    = "phpf/" + obj.grid_url + "?tbl=" + obj.pagr_lent + "&idf=" + obj.pagr_rakt + "&idk=" + row[ obj.pagr_rakt ] + "&cmd=upd&lks=" + laukas + "&var=" + reiksm +
   "&fld=" + obj.lauku_eil + ( obj.rysio_eil ? "&jon=" + obj.rysio_eil : "" ); // update query to php ...
   
   var ret = ajax_get( snd );
   if ( ret.status != 'success' )
      alert( ret.message );
   else
   {
      var upd = 0; // check if other related field updated or not
      var rec = ret.rows;
      for ( var u in obj.grid_stulp )
      {
         var lks = obj.grid_stulp[ u ].field;
         if ( rec[ 0 ][ lks ] != row[ lks ] )
         {
            row[ lks ] = rec[ 0 ][ lks ];
            upd ++;
         }
      }
      if ( upd > 0 ) // if returned record differs from existing row - update
         dg.datagrid( 'updateRow', { index: index, row: row } );
   }
}

At first I thinked that this cell update is related to typing for filters ..., but disabling "onAfterEdit" nothing changed, the same problem ... :(

How to solve that conflict between filter and cells editors ?


Many thanks in advance ...