question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic ngTable in array

See original GitHub issue

Hi, I’m facing some issues trying to show multiple ngTable declared into an array.

var dataDest = [[]];
$scope.tableParamsDest = [];
$scope.values = [[]];

for (var i = 0; i < 4; i++) {
    dataDest[i] = [];

    $scope.tableParamsDest.push(
                new ngTableParams({
                page : 1,
                count : 10, 
                }, {
                    total : dataDest[i].length, // length of data
                    getData : function($defer, params) {
                        $defer.resolve($scope.values[i] = dataDest[i].slice((params.page() - 1)
                                * params.count(), params.page()
                                * params.count()));
                    }
                }));
}

As you can see, each ngTable data is bound to dataDest[i]; these are filled later, calling a server routine when the user press on a button. I pass the index of the current table to the function that updates the dataDest[i], so I’m sure I update the right data of the right table, then i call the $scope.tableParamsDest[$index].reload();

The html looks like the following:

<div  ng-repeat="template in templateList" class="container">
  ...
  <table class="table" ng-table="tableParamsDest[$index]">
         <tr ng-repeat="user in $data">
             <td header="'ng-table/headers/checkbox.html'"><input type="checkbox" ng-model="checkboxesDest[$parent.$index].items[$index]"></td>
              <td data-title="'Name'">{{user.name}}</td>
               <td data-title="'Email'">{{user.email}}</td>
     </tr>
  </table>
  <script type="text/ng-template" id="ng-table/headers/checkbox.html"><input type="checkbox" ng-model="checkboxes.checked" id="select_all" name="filter-checkbox" value="" /></script>              
...                                                              

The first time I add items to dataDest[i] and reload the linked ngTable, all works properly. If I add some items to another table, dataDest[i] of this table are correctly updated, but after the reload I see within the second table the data added in the first table! What could be the problem? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Andy000commented, Sep 17, 2015

Yes! I moved the tables creation in another function which takes an index as parameter and now everything works, thanks Christian. If I am correct, the issue is somehow related to this so question: http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example

getData, being the inner function, was always bound to the same i value.

0reactions
christianaccacommented, Sep 29, 2015

cool glad you found a solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using dynamic arrays with other Excel features
Dynamic arrays have a love/hate relationship with Excel tables. If we use Excel tables as the source for a dynamic array formula, everything ......
Read more >
Dynamic array formulas and spilled array behavior
Excel formulas that return a set of values, also known as an array, return these values to neighboring cells. This behavior is called...
Read more >
Create a dynamic table from and array - ServiceNow Community
Hi, I need some assistance on creating a dynamic table from an array. I want the configuration item to be a fixed header...
Read more >
Displaying data from arrays in a dynamic table PHP
I'm trying to display this data in a 4 row 5 column table using PHP. I try to use a foreach loop that...
Read more >
Excel Dynamic array | Exceljet
Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found