3

I am trying to set the editableCellTemplate ColumnDef option in a ng-grid (documented here).

When I do set it, even to the default value of <input ng-class="'colt' + col.index" ng-input="COL_FIELD" />, clicking on a cell immediately gives the error

Error: No controller: ngModel at Error () at getControllers (http://foo.com:43037/Scripts/angular.js:4232:19) at nodeLinkFn (http://foo.com:43037/Scripts/angular.js:4361:35) at compositeLinkFn (http://foo.com:43037/Scripts/angular.js:3969:15) at compositeLinkFn (http://foo.com:43037/Scripts/angular.js:3972:13) at publicLinkFn (http://foo.com:43037/Scripts/angular.js:3874:30) at Object. (http://foo.com:43037/Scripts/ng-grid-2.0.7.js:2660:13) at Object.applyFunction [as fn] (:778:50) at Object.Scope.$digest (http://foo.com:43037/Scripts/angular.js:7896:27) at Object.$delegate.proto.$digest (:844:31) <input ng-class="'colt' + col.index" ng-input="row.entity.Name">

If I do not set editableCellTemplate, editing cells work just fine.

$scope.gridOptions = {
    data: 'people',
    enableCellSelection: true,
    enableRowSelection: false,
    enableCellEdit: true,
    columnDefs:
    [
        { field: 'Id', displayName: 'ID', enableCellEdit: false },
        { field: 'Name', enableCellEdit: true, 
          editableCellTemplate: '<input ng-class="\'colt\' + col.index" ng-input="COL_FIELD" />' }
    ]
};

What is wrong?

(The problem I am actually trying to solve is creating an event when cell edit ends, but that solution assumes that you can set a cell template)

Community
  • 1
  • 1
Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158

1 Answers1

8

Your template for input needs to have an ng-model attribute defined as well:

<input ng-class="'colt' + col.index" ng-input="COL_FIELD" ng-model="COL_FIELD" />

this is the default editableCellTemplate.

Davin Tryon
  • 66,517
  • 15
  • 143
  • 132
  • 3
    This worked nicely, thank you. The "default" value that I got was copy-pasted from the API documentation, http://angular-ui.github.io/ng-grid/#api, which lacks the ng-model attribute. Looks like a documentation bug to me. – Klas Mellbourn Aug 23 '13 at 12:13
  • 1
    Thanks! this actually works.. but I'd like to understand why I have to use both ng-model and ng-input: what is their exact meaning? – Luke Sep 18 '14 at 14:33
  • Totally agree Luke, there are lots of magical incantations for the value of editableCellTemplate. What is 'colt'#? What is COL_FIELD? What is ng-input? – steve Oct 09 '14 at 17:02