angularjs - Cell class change is postponed till next edit or scroll -


i'm trying mark edited in ui grid cell blue color. purpose in aftercelledit event make changes in row entity. cellclass function checks these marks , returns corresponding class name. call $scope.$apply (specified in documentation) used.

following example simplified there no check, column has been edited. in real app have more complicated code mark specific cell. example enough show problem:

  1. select cell in company column (but not in last row).
  2. change value there.
  3. press enter.
    tha value changes, edited column changes true, selection moves next row, the text in edited cell still black.
  4. press enter again.
    text in edited on step 2 cell becomes blue.

how can force color change on step 3 instead of 4?

http://plnkr.co/edit/seef4dpha3cb1mx7r4i8?p=preview

var app = angular.module('app', ['nganimate', 'ngtouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit', 'ui.grid.cellnav']);    app.controller('mainctrl', ['$scope', '$http', function ($scope, $http) {    $scope.gridoptions = {      enablecelleditonfocus: true,            columndefs: [{        field: 'edited',        enablecelledit: false      },{        field: 'company',        cellclass: function(grid, row, col, rowrenderindex, colrenderindex) {          return row.entity.edited ? 'blue' : '';        }      }],            onregisterapi: function (gridapi) {        gridapi.edit.on.aftercelledit($scope, function (rowentity, coldef, newvalue, oldvalue) {          if (newvalue !== oldvalue) {            rowentity.edited = true;            $scope.$apply();          }        });      }    };      $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')      .success(function(data) {        $scope.gridoptions.data = data;      });  }]);
.grid {    width: 500px;    height: 200px;  }    .blue {    color: blue;  }
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>  <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>  <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>  <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>  <script src="http://ui-grid.info/release/ui-grid.js"></script>  <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">  <link rel="stylesheet" href="main.css" type="text/css">    <div ng-app="app" ng-controller="mainctrl">    <div id="grid1" ui-grid="gridoptions" ui-grid-selection ui-grid-edit ui-grid-cellnav class="grid"></div>

ps: same question in russian.

you can use notifydatachange let uigrid know value has changed.

juste inject uigridconstants in controller , replace $scope.apply() gridapi.core.notifydatachange(uigridconstants.datachange.column);

var app = angular.module('app', ['nganimate', 'ngtouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit', 'ui.grid.cellnav']);      app.controller('mainctrl', ['$scope', '$http','uigridconstants', function ($scope, $http,uigridconstants) {     $scope.gridoptions = {     enablecelleditonfocus: true,      columndefs: [{       field: 'edited',       enablecelledit: false     },{       field: 'company',       cellclass: function(grid, row, col, rowrenderindex, colrenderindex) {         return row.entity.edited ? 'blue' : '';       }     }],      onregisterapi: function (gridapi) {       gridapi.edit.on.aftercelledit($scope, function (rowentity, coldef, newvalue, oldvalue) {         if (newvalue !== oldvalue) {           rowentity.edited = true;           gridapi.core.notifydatachange(uigridconstants.datachange.column);         }       });     } };  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')     .success(function(data) {       $scope.gridoptions.data = data;     }); }]); 

a working plunker : http://plnkr.co/edit/grsektm6ef2cdwinhxm7?p=preview


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -