angularjssmart-table

Resetting single row values


I am using smart-table to display tabular data. One column of the table is editable. It is displayed and edited in an input field. Each row has a reset button which is supposed to reset edits made in the input field to the initial state.

How do I reset values of a single row (input field) when using smart-table?

Specifically what needs to be in the following function:

$scope.resetItem = function(index) {
  // .....
};

Solution

  • I don't know about smart-table but why don't you try to get a copy of the data upfront and replace the related row with the original one?

    var initialData = angular.copy(data);
    $scope.data = data;
    $scope.resetItem = function(index) {
      $scope.data[index] = angular.copy(initialData[index]);
    }