Angularjs 如何使用动态数据刷新从http请求加载的NG表

Angularjs 如何使用动态数据刷新从http请求加载的NG表,angularjs,http,ngtable,Angularjs,Http,Ngtable,我需要能够刷新ng表中的数据。以下图像包含完整的用例场景。 当用户单击搜索BrandID时,将显示一个新的模式窗口: 它包含一个ng表,其中包含一些加载的数据。模式被取消后,我单击第二个搜索(GroupID),在这里打开了带有ng表的相同模式窗口,但即使请求正常且数据从服务器返回,加载也失败: 我希望能够刷新该表,以便使用新接收的数据对其进行初始化 每次模式切换时都会调用中的脚本。尝试以下操作以更新表数据: $scope.tableParams.reload(); 编辑: 我在你的代码中发

我需要能够刷新ng表中的数据。以下图像包含完整的用例场景。 当用户单击搜索BrandID时,将显示一个新的模式窗口:

它包含一个ng表,其中包含一些加载的数据。模式被取消后,我单击第二个搜索(GroupID),在这里打开了带有ng表的相同模式窗口,但即使请求正常且数据从服务器返回,加载也失败:

我希望能够刷新该表,以便使用新接收的数据对其进行初始化


每次模式切换时都会调用中的脚本。

尝试以下操作以更新表数据:

$scope.tableParams.reload();
编辑: 我在你的代码中发现了一个可能的错误。。。 我认为你应该改变这一点:

var orderedData = params.sorting() ?
   $filter('orderBy')(filteredData, params.orderBy()) :
   $scope.datay;
为此:

var orderedData = params.sorting() ?
   $filter('orderBy')(filteredData, params.orderBy()) :
   filteredData;

这样做更好吗?

可以找到问题的解决方案。这不是一个好的解决方案,但现在它是最好的。通过对每个请求强制不同的计数,表将重新加载其数据,您将获得所需的结果。可以找到新的Plunk 请注意每个请求的每页计数不同的重要性。如果count属性设置为相同的数字,则解决方案将失败。
我希望这能说明问题,我也希望ng table的开发人员能够解决这个问题

这个代码示例似乎有效,请检查这个SO问题以获得更多解释:


各位,现在我支持回购协议,并最终发行了固定资产

如果表基于模型,则不需要刷新它。Angular会自动执行(ngRepeat有自己的观察者)。只需使用
添加新产品
表单(aka
formList.push(createdForm);
)绑定表格模型即可。@Maxim表格不基于ng模型。这是搜索时显示的模式窗口,请检查plunker html。模态窗口不用于添加整个产品,它们仅用于向formHi的cetain字段中添加一些属性,解决方案不起作用,因为如果在初始化之前使用新数据重新加载表,将出现未定义数据的错误。感谢您的回答,但它仍然无法解决问题。我找到了一个解决办法,我将在回答中发布。嗨,在这个回购协议中,哪里有一个例子或解释?
// Get data from factory
var data = dataFactory.query();

//Use promise to load data to table, note the replacing of the second tableParams 
//object parameter with a function
data.$promise.then(function (data){
    $scope.tableParams = new ngTableParams({
        page: 1,            // show first page
        count: 10,
        sorting: {
            name: 'asc'
        },
        filter: {
            name: undefined             
        }
    }, resetTableParams()
    );
});

//The function that replaces the tableParams param
var resetTableParams = function(){
    return {
        total: data.length,
        getData: function($defer, params) {
            var filteredData = params.filter() ? $filter('filter')(data,    params.filter()) : data;
        var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : filteredData; 

        params.total(orderedData.length);
        $defer.resolve($scope.data = orderedData.slice((params.page() -1) * params.count(), params.page() * params.count()));           
        }
    }
}

//A method to update the table that can be called when closing a modal
var updateTable = function(){
    data = dataFactory.query();
    data.$promise.then(function (data){
        $scope.tableParams.reload();
    });
}

// Add table row to table in modal and call updateTable() on closing modal
$scope.addRow = function(){
    var modalInstance = $modal.open({
        templateUrl: 'resources/partials/newrecord.html',
        controller: NewRecordModalCtrl
    })

    modalInstance.result.then(function(){
        updateTable();
    });
}