Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a better way to toggle in and out of edit mode in ng-grid?
    primarykey
    data
    text
    <p>So far I've only been able to change the edit mode in ng-grid by using separate templates and displaying the correct template based on some user input. </p> <p>Example: <a href="http://plnkr.co/edit/AUJtlmt6TiysaacdWMZF?p=preview" rel="nofollow"><strong>Plunker</strong></a> (re-size a column and then switch to another mode)</p> <p>This is an issue because any column re-sizing, sorting, or grouping that is preformed is lost when switching from template to template. </p> <p>Is there a better approach?</p> <h2>Workaround</h2> <p>If anyone is interested, I created a workaround for myself by modify ng-grid.js 2.0.7</p> <p>First I modified the cellEditTemplate.html and added the attribute disable-Cell=\"!isEditing\" (isEditing is a scope variable from the controller which would be required with this workaround)</p> <pre><code> $templateCache.put("cellEditTemplate.html", "&lt;div ng-cell-has-focus disable-Cell=\"!isEditing\" ng-dblclick=\"editCell()\"&gt;\n" + "\t&lt;div ng-edit-cell-if=\"!isFocused\"&gt;\t\n" + "\t\tDISPLAY_CELL_TEMPLATE\n" + "\t&lt;/div&gt;\n" + "\t&lt;div ng-edit-cell-if=\"isFocused\"&gt;\n" + "\t\tEDITABLE_CELL_TEMPLATE\n" + "\t&lt;/div&gt;\n" + "&lt;/div&gt;" ); </code></pre> <p>Then I modified the ngCellHasFocus directive and added a $watch on the disableCell attribute. When disableCell is set to true I prevent the click and mousedown event from firing in that directive. </p> <pre><code> return function ($scope, elm, attrs) { var disabled = false; //Added $watch $scope.$watch(attrs.disableCell, function (newVal) { disabled = newVal; }); var isFocused = false; var isCellEditableOnMouseDown = false; $scope.editCell = function () { if (!$scope.enableCellEditOnFocus) { setTimeout(function () { focusOnInputElement($scope, elm); }, 0); } }; elm.bind('mousedown', function (evt) { //Added return if (disabled) return; if ($scope.enableCellEditOnFocus) { isCellEditableOnMouseDown = true; } else { elm.focus(); } return true; }); elm.bind('click', function (evt) { //Added return if (disabled) return; if ($scope.enableCellEditOnFocus) { evt.preventDefault(); isCellEditableOnMouseDown = false; focusOnInputElement($scope, elm); } }); elm.bind('focus', function (evt) { isFocused = true; if ($scope.enableCellEditOnFocus &amp;&amp; !isCellEditableOnMouseDown) { focusOnInputElement($scope, elm); } return true; }); elm.bind('blur', function () { isFocused = false; return true; }); elm.bind('keydown', function (evt) { if (!$scope.enableCellEditOnFocus) { if (isFocused &amp;&amp; evt.keyCode !== 37 &amp;&amp; evt.keyCode !== 38 &amp;&amp; evt.keyCode !== 39 &amp;&amp; evt.keyCode !== 40 &amp;&amp; evt.keyCode !== 9 &amp;&amp; !evt.shiftKey &amp;&amp; evt.keyCode !== 13) { focusOnInputElement($scope, elm); } if (isFocused &amp;&amp; evt.shiftKey &amp;&amp; (evt.keyCode &gt;= 65 &amp;&amp; evt.keyCode &lt;= 90)) { focusOnInputElement($scope, elm); } if (evt.keyCode === 27) { elm.focus(); } } return true; }); }; }]); </code></pre> <p>And here are my grid options</p> <pre><code> $scope.gridOptions = { data: 'myData', enableColumnResize: true, enableCellSelection: true, enableRowSelection: true, enableCellEditOnFocus: true, columnDefs: 'columnDefs', plugins: [layoutPlugin], //My row template has a ng-dblClick() attached to it for navigation in non-edit mode rowTemplate: 'Templates/gridRowView.html' }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload