ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

[ui-grid 3.0.0-rc16] Edited row does not get marked as dirty after clicking off to another row

Open pmariduena opened this issue 12 years ago • 5 comments

I read the tutorials and API but I am still not sure what options I need (maybe I've been looking at this too long).

When I double-click a cell, that lets me edit it (and the rest of the row). However, when I'm done editing the row (or even just edit one cell), I expect the text to turn red, but it never does. It only turns red when I start editing a cell in another row (by double clicking on it).

I expect for the row to turn red (become dirty) when I single click another row. I expect, however, for edits to start only on a double click.

What I am doing wrong in my options? Here's details on my grid:

I'm implementing a ui-grid that doesn't attempt to persist the rows until you hit a "Save Rows" button. When you press it, various $resource REST calls are made to call a REST service on the backend to persist additions, deletions, updates to a database.

As such, here are my grid modules and options:

<div class="gridStyle" ui-grid="gridOptions" ui-grid-edit ui-grid-resize-columns ui-grid-row-edit ui-grid-cellnav ui-grid-selection>

        $scope.gridOptions = {
            columnDefs: [
                {field: 'id', displayName: 'Identifier', enableCellEdit: true},
// other colDefs
            ],
            data: $scope.myData,
            enableCellSelection: true,
            enableColumnResizing: true,
            enableFiltering: true,
            enableGridMenu: true,
            enableRowSelection: true,
            minRowsToShow: 50,
            multiSelect: true,
            rowHeight: 20,
            rowEditWaitInterval: -1,
            showFooterRow: false
        };

I have registered these event handlers ():

$scope.gridOptions.onRegisterApi = function(gridApi) {
    $scope.gridApi = gridApi;
    gridApi.selection.on.rowSelectionChanged($scope, function(row) {...});
    gridApi.edit.on.afterCellEdit( $scope, function( rowEntity, colDef ) {...});
    gridApi.rowEdit.on.saveRow($scope, function(rowEntity){...});
};

Eventually, I call the following when I hit the Save button:

$scope.gridApi.rowEdit.flushDirtyRows($scope.gridApi.grid);

which, in turn, triggers the saveRow() callback for every row that was added/modified (any dirty rows). This resolves all the promises on the rows.

pmariduena avatar Nov 21 '14 03:11 pmariduena

Does it behave as you expect in the tutorial? If not, then the answer might be that your expectations are wrong.

If the tutorial behaves as you expect, and your code doesn't, then I'd suggest setting your options exactly as they are in the tutorial and then changing the options one by one to your preferred settings and see which option is changing the behaviour that you expect.

PaulL1 avatar Nov 21 '14 03:11 PaulL1

@PaulL1 I'll take a second look at my code and compare with the tutorial.

pmariduena avatar Nov 21 '14 03:11 pmariduena

@PaulL1 I'm reopening this as I have gone through the tutorial, and notice a difference between it and the behavior I see, and I believe this could be a bug, or at least something that needs to be accounted for with a workaround....please read the restatement below.

I followed Tutorial 205, running code 3.0.0-rc16, and I'm having trouble showing the row as "dirty" (or dark red) in the UI after editing the most recently edited row (so it could be the fist row). I don't want to use the auto-save feature, I want to save when I explicitly click a "Save" button that calls "flushDirtyRows".

Here's what I see as behavior (> means console output)

after first row edit:

stop edit! onAfterCellEdit event triggered for row: myRow

click off once to a cell in a different row:

(nothing on console, row doesn't appear dirty since it is not marked dark red)

start 2nd edit on original row:

(nothing on console, but now row is marked as Dirty, dark red)

finish 2nd edit on original row:

stop edit! onAfterCellEdit event triggered for row: myRow

This is not so serious from a functional perspective, as all modified rows do eventually end up getting accounted for when I click the "Save button"

I think this is occuring because I am setting "rowEditWaitInterval" to -1, since I don't want a save to happen until the user explicitly presses save. I'm guessing it's not triggering some event that would normally occur if rowEditWaitInterval were a positive integer. A digest cycle is not happening or something.

here are the gridOptions I have: enableCellSelection: true, enableColumnResizing: true, enableFiltering: true, enableGridMenu: true, enableRowSelection: true, minRowsToShow: 50, multiSelect: true, rowHeight: 20, rowEditWaitInterval: -1, showFooterRow: false

here are the even handlers I've registered (similar to the tutorial): $scope.gridOptions.onRegisterApi = function(gridApi) { $scope.gridApi = gridApi;

            gridApi.selection.on.rowSelectionChanged($scope, function(row) {
                if(row.isSelected) {
                    var msg = 'row selected ' + $scope.gridOptions.getRowIdentity(row.entity);
                    $log.log(msg);
                } else {
                    $log.log('unselected row: ' +  $scope.gridOptions.getRowIdentity(row.entity));
                }
            });

            gridApi.edit.on.afterCellEdit( $scope, function( rowEntity, colDef ) {
                var dirtyRows = $scope.gridApi.rowEdit.getDirtyRows($scope.gridApi.grid);
                $log.log('onAfterCellEdit event triggered for row: '
                    + $scope.gridOptions.getRowIdentity(rowEntity));
            });

    // this is invoked when I call flushDirtyRows in the Save method
    // saveMyRows works fine and resolves all promises on each row.
            gridApi.rowEdit.on.saveRow($scope, $scope.saveMyRows);

}

Is there any way to get around this for this mode of editing with ui-grid?

pmariduena avatar Nov 21 '14 20:11 pmariduena

If I modify the base rowEdit tutorial to have a waitInterval of -1 then it is correctly marking the rows as dirty in dark red: http://plnkr.co/edit/3GGl8019gBeOGpgC6ZK2?p=preview

I suspect your problem is the newly created rows not being marked dirty if you do no edits on them at all. The reason for this is that the creation of the row does not result in the row being marked dirty, as there is no edit event.

My suggestion is to modify your add method to also set the row dirty when it is created: http://plnkr.co/edit/3GGl8019gBeOGpgC6ZK2?p=preview

PaulL1 avatar Nov 21 '14 23:11 PaulL1

Explicitly marking the row dirty appears to work for me as in your example..Thanks.

pmariduena avatar Nov 25 '14 15:11 pmariduena