NgTable.reload () cannot update ng-table, second time does not show new data

ngTable.reload()

unable to update ng-table does not show new data second time

code for index.js where I am binding ng-table data.

Work in real time. the second time the data is optional. it shows previous data. so basiccally it cannot bind data and cannot update

 $http.get("GetValidationsDataForTable", { params: { "entity": entity } })
                 .success(function (response) {
                     $scope.tableValue = response;
                     $scope.tableParams = [];
                     $scope.tableParams = new ngTableParams(
                         {
                             page: 1,            // show first page
                             count: 5          // count per page
                         },
                         {
                             groupBy: 'Entity',
                             total: $scope.tableValue.length,
                             getData: function ($defer, params) {

                                 var orderedData = params.filter() ?
                            $filter('filter')($scope.tableValue,    params.filter()) :
                            $scope.tableValue;

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

                                 orderedData = params.filter ?
                            $filter('filter')(orderedData, params.filter()) :
                            orderedData;
                                 params.total(orderedData.length);
                                 $defer.resolve($scope.tableValue.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                             }
                         });
                     $scope.tableParams.reload();
                 })

      

code for index.cshtml

  <table id="tblValue" ng-table="tableParams" class="customTable" style="table-layout:fixed;max-width:100%">
                    <tbody ng-repeat="group in $groups">


                        <tr ng-hide="group.$hideRows" ng-repeat="validation in group.data" style="table-layout:fixed;">

                            <td data-title="'Property'" style="width:10%;text-align:left !important;overflow:hidden;">
                                <label id="lblProperty" ng-model="validation.Property" for="Property" ng-hide="editmode" style="width:97%;word-wrap:break-word; overflow-wrap:break-word;">{{validation.Property}}</label>

                                <select class="form-control" data-ng-model="validation.PropertyChoice" data-ng-options="choice.Name for choice in CurrentEntityProperties" ng-change="ChangeValidationRules(validation)" ng-show="editmode" style="width:100%; ">
                                    <option value="" style="margin-left:25px">-Select Property-</option>
                                </select>

                            </td>
                        </tr>
                    </tbody>
                </table>

      

why is ngtable.reload () not working and also not showing new data a second time?

+3


source to share


3 answers


The solution to this problem is to place spaces before any data requests.



$scope.GetValidationsDataForTable = function(entity) {

    // $("div").removeClass("container body-content");

    $scope.tab1eParams = {};
    SpinStart();
    $http.get("GetValidationsDataForTable", {
        params: {
            "entity": entity
        }
    }).success(function(response) {
        var resultArray = response;
        SpinStop();
        if (!$.isArray(resu1tArray) || !resultArray.1ength) {
            $scope.HideFormVa1ue();
            alert("Ho record found for this selection.");
        }
        else {

            $scope.ShowFormVa1ue();
            $scope.rows = response;
            $scope.groupby = 'Entity',
            $scope.tab1eParams = new ngTableParams({
                page: 1,
                count: 50,
                filter: {},
                sorting: {}
            },
            {
                groupBy: $scope.groupby,
                counts: [],
                total: function() {
                    return $scope.rows.1ength;
                },
                getData: function($defer, params) {
                    $defer.resolve($scope.rows.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                }
            });

      

0


source


Decision:

$scope.tableParams = {};
    $http.get("GetValidationsDataForTable", { params: { "entity": entity } })
                 .success(function (response) {
                     $scope.tableValue = response;
                     $scope.tableParams = [];
                     $scope.tableParams = new ngTableParams(
                         {
                             page: 1,            // show first page
                             count: 5          // count per page
                         },
                         {
                             groupBy: 'Entity',
                             total: $scope.tableValue.length,
                             getData: function ($defer, params) {

                                 var orderedData = params.filter() ?
                            $filter('filter')($scope.tableValue,    params.filter()) :
                            $scope.tableValue;

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

                                 orderedData = params.filter ?
                            $filter('filter')(orderedData, params.filter()) :
                            orderedData;
                                 params.total(orderedData.length);
                                 $defer.resolve($scope.tableValue.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                             }
                         });
                     $scope.tableParams.reload();
                 })

      



ie before each request, make the table parameters empty.

0


source


You must clone params.filter()

before using your service and use params.filter().yourFilter

HTML in your data binding.

So you don't need to use reload()

, it will ngTable

reboot automatically.

Sincerely.

0


source







All Articles