Giter Site home page Giter Site logo

Comments (8)

jonricaurte avatar jonricaurte commented on June 15, 2024

Use $scope.$digest() after you push
On Dec 19, 2012 4:44 PM, "eu81273" [email protected] wrote:

When clicked an item in First grid then that item is moved into Second
grid.
When I use ng-grid v1.4.0, the routine below works fine.
But now 1.4.1, ng-grid cannot recognize the data changes immediately.

Did I wrong something?

//assgined user list
$scope.assignedUsers = [];

//all user list
$scope.registeredUsers = [];

$scope.assignedUserGridOptions =
{
data: 'assignedUsers',
columnDefs:
[
{
field: 'userId',
displayName: 'id'
},
{
field: 'userName',
displayName: 'name'
},
{
field: 'enabled',
displayName: 'available'
}
],
rowTemplate: '
',
footerVisible: false,
multiSelect: false,
showColumnMenu: false,
canSelectRows: false,
displaySelectionCheckbox: false,
showFilter: true
};

$scope.registeredUserGridOptions =
{
data: 'registeredUsers',
columnDefs:
[
{
field: 'userId',
displayName: 'id'
},
{
field: 'userName',
displayName: 'name'
},
{
field: 'enabled',
displayName: 'available'
}
],
rowTemplate: '
',
footerVisible: false,
multiSelect: false,
showColumnMenu: false,
canSelectRows: false,
displaySelectionCheckbox: false,
showFilter: true
};

//remove clicked item from "assigned" user list and add the item to "all"
user list
$scope.remove = function(userId)
{
for(var i in $scope.assignedUsers)
{
if($scope.assignedUsers[i].userId == userId)
{
$scope.registeredUsers.push($scope.assignedUsers.splice(i, 1)[0]);
break;
}
}

//If skip cords below, ng-grid cannot recognize data changed.
$scope.assignedUsers = JSON.parse(JSON.stringify( $scope.assignedUsers ));
$scope.registeredUsers = JSON.parse(JSON.stringify( $scope.registeredUsers ));

};

//remove clicked item from "all" user list and add the item to "assigned"
user list
$scope.insert = function(userId)
{
for(var i in $scope.registeredUsers)
{
if($scope.registeredUsers[i].userId == userId)
{
$scope.assignedUsers.push($scope.registeredUsers.splice(i, 1)[0]);
break;
}
}

//If skip cords below, ng-grid cannot recognize data changed.
$scope.assignedUsers = JSON.parse(JSON.stringify( $scope.assignedUsers ));
$scope.registeredUsers = JSON.parse(JSON.stringify( $scope.registeredUsers ));

};


Reply to this email directly or view it on GitHubhttps://github.com//issues/59.

from ui-grid.

eu81273 avatar eu81273 commented on June 15, 2024

I tried use $scope.$digest() after push but an error occurs like below.

Error: $apply already in progress
at Error ()
at g (http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:82:382)
at Object.e.$digest (http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:84:130)
at Object.$scope.remove (http://localhost:8080/common/angularJs/resources/js/roleAuthorityListController.js:287:10)
at http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:70:328
at http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:139:402
at Object.e.$eval (http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:86:220)
at Object.e.$apply (http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:86:327)
at HTMLDivElement. (http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:139:384)
at HTMLDivElement.f.event.dispatch (http://localhost:8080/common/angularJs/libs/jquery/js/jquery-1.7.1.min.js:3:4351)

from ui-grid.

orneryd avatar orneryd commented on June 15, 2024

We may need to rethink the data watching.... In angular if we call apply()
when the rendered rows change we take a huge performance hit. If we call
digest(), it seems that the rows do not get updated in all cases...

On Wednesday, December 19, 2012, Steve wrote:

I tried use $scope.$digest() after push but an error occurs like below.

Error: $apply already in progress
at Error ()
at g (
http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:82:382
)
at Object.e.$digest (
http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:84:130
)
at Object.$scope.remove (
http://localhost:8080/common/angularJs/resources/js/roleAuthorityListController.js:287:10
)
at
http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:70:328
at
http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:139:402
at Object.e.$eval (
http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:86:220
)
at Object.e.$apply (
http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:86:327
)
at HTMLDivElement. (
http://localhost:8080/common/angularJs/libs/angularjs/js/angular.min.js:139:384
)
at HTMLDivElement.f.event.dispatch (
http://localhost:8080/common/angularJs/libs/jquery/js/jquery-1.7.1.min.js:3:4351)


Reply to this email directly or view it on GitHubhttps://github.com//issues/59#issuecomment-11556466.

-Tim Sweet

from ui-grid.

orneryd avatar orneryd commented on June 15, 2024

I think I know why it was automatic before.
we added a flag to prevent the grid from re-rendering when selecting an object:

if (grid.skipDataWatch) {
    grid.skipDataWatch = false;
    return;
}

when you select the object in the grid we are no longer not firing the watch function, which it was before (which was unintended).

we set it when marking data as selected we set that flag to true.

from ui-grid.

orneryd avatar orneryd commented on June 15, 2024

we modified the way we watch the data. We now watch the length of the array instead, so push-pop-splice is the preferred method of adding or removing data to the array now.

from ui-grid.

xelab avatar xelab commented on June 15, 2024

It seems there's a problem when i splice the data array but don't change the length (i only replace an object by another): ng-grid doesn't update display. For the moment i make a full copy of the old array, splice the new value and reassign the new array to my true data object. It works but it's not very nice...

from ui-grid.

c0bra avatar c0bra commented on June 15, 2024

@xelab that's a limitation with the current stable version of angular, and how the grid works. ng-grid only does a "shallow" watch on the data reference, which means it updates the grid if the data length changes or the reference itself changes. It does not update if deeper-level values change. Doing a "deep" watch is possible, but it comes with an extreme performance hit.

In 3.0 and newer versions of angular it will be possible to update in the manner you're wanting.

from ui-grid.

mattborack avatar mattborack commented on June 15, 2024

You could locate the $scope.$$watcher that is watching the length of the array and alter its 'last' property. Using the underscore.js lib, I use something like the following:

var watcher = _.find($scope.$$watchers, function (watcher) { return watcher.exp == 'myData.length' });
if (watcher) { watcher.last = -1; }

from ui-grid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.