angular-ui-grid load state on controller creation -


i want load last state of ui-grid when controller created. i've set plunkr. http://plnkr.co/edit/cohluuabvstfoth6qvzd?p=preview in controller use restoreonload function called @ end of controller. typeerror: cannot read property 'savestate' of undefined because gridapi undefined @ time of controller creation.

restoreonload = function(){   //retrieve stateinfo. simplicity: inline object...   var stateinfo = {     "columns": [         {             "name": "",             "visible": true,             "width": 50,             "sort": {                 "direction": "asc",                 "priority": 0             },             "filters": [             ]         },         {             "name": "m",             "visible": true,             "width": 50,             "sort": {             },             "filters": [             ]         },         {             "name": "company",             "visible": true,             "width": 200,             "sort": {             },             "filters": [             ]         }     ],     "scrollfocus": {     },     "selection": {     }   }   $scope.gridapi.savestate.restore($scope, stateinfo); }  restoreonload(); 

any ideas how avoid error?

your restore call running before grid's api registered, need wait happen.

you can move restoreonload() call onregisterapi handler:

vm.gridoptions = {   onregisterapi: function (gridapi) {     $scope.gridapi = gridapi;     restoreonload();   } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -