angularjs-table icon indicating copy to clipboard operation
angularjs-table copied to clipboard

Add possibility to update one record

Open bestin-it opened this issue 7 years ago • 1 comments

Sometimes you want to update one record in your table. It would be nice (especially in server version) to update one record without loading whole dataset from server. Function might look like below:

    $scope.updateRecord = function(row)
    {
        var columns = $scope.columns;
        var selectorKey = null;
        var selectObject = null;
        // Search for selector key in selector column
        for (var i = 0; i < columns.length; i++) {
            if (columns[i].selector) {
                selectorKey = columns[i].key;
                selectObject = columns[i].selectObject;
                break;
            }
        }

        for (var i = 0; i < $scope.visible_rows.length; i++) {
            if ($scope.visible_rows[i][selectorKey] === row[selectorKey])
            {
                $scope.visible_rows[i] = row;
            }
        }

    }

bestin-it avatar Sep 22 '17 20:09 bestin-it

Again, sorry for the late response.

First of all, if you update the object's properties (i.e., not replace the object), it should be reflected in the table. If it is not, then this is a bug.

If, on the other hand, you need to entirely replace the row object, you could potentially do this:

// assuming scope.data is passed to the `rows` attribute,
// `indexToChange` is the master index of the row you want to replace,
// and `replacementObject` is the object to replace the row with
scope.data[indexToChange] = replacementObject;
scope.$broadcast('apMesa:forceRefresh');

I have not tested this so you'll need to try this out and let me know if that works. If it doesn't, it may merit an additional method added to the api object.

Let me know, and I will try to find time to add that functionality. PRs are also welcome!

andyperlitch avatar Dec 14 '17 19:12 andyperlitch