Open scne opened 9 years ago
I cannot change the code for yours, because I lack context, but this works for me: Also, I dont know how to mark code, so just copy/paste it to view it correctly. My getData function:
getData: function ($defer, params) { var filteredData = params.filter() ? $filter('filter')(scope2[data], params.filter()) : scope2[data]; var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : scope2[data];
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
My delete row function:
scope[table].removeRow = function (identifier, value) { scope2[data] = $.grep(scope2[data], function (v) { return v[identifier] != value; }); };
I call it like: removeRow('id',7); so it will remove all lines with id of 7.
at the end of the function you can have "this.reload()" or as i have done (because I have more functions like add etc..) do a watch:
scope2.$watch(data, function () { scope[table].reload(); }, true);
I am expanding the ngtable class to be called remotly, with a url, have an add, delete, and more settings, for my project I have to use it alot. If you found this useful, and think you have knoladge on the class, please check my issue: https://github.com/esvit/ng-table/issues/724
I use this way to delete row from my list. `$scope.tableParams = new NgTableParams({ count:10,
}, {
// getData: function ($defer, params){
// $defer.resolve();
// }
total: 0,
filterDelay:300,
getData:function($defer, params){
$http.get('representatives.json').success(function(d){
$scope.representatives=d.results;
$defer.resolve($scope.representatives);
})
}
});
$scope.removePre=function(){
var reps=$scope.representatives;
for(var i=reps.length-1; i>-1; i--){
if(reps[i].selected==1){
reps.splice(i, 1);
}
}
$scope.tableParams.settings({
dataset:$scope.representatives //reset the data for ng-table
})
}`
Hi! I've some troubles with ng-table. I would like to remove a row and delete if from table. This is a part of my code. In this way I fill my table
And I've this for remove item from server and catch response
But nothing happening when reload....