Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs ui-grid onRegisterApi event

can someone explain me what is purpose of gridApi in ui-grid and purpose of onRegisterApi event? And what is order of event when grid is rendering?

like image 842
VirtuoZ Avatar asked Dec 23 '15 19:12

VirtuoZ


2 Answers

Here's the docs, and here's a quick run-down:

GridApi provides the ability to register public methods events inside the grid and allow for other components to use the api via featureName.raise.methodName and featureName.on.eventName(function(args){}). To listen to events, you must add a callback to gridOptions.onRegisterApi

So basically you need to provide a callback for each of the events that you want to listen on.

About your second question, the order of events when the gird is rendering. The of events doesn't matter since in this phase you only register to the events that you want to handle.

Here are couple of examples that might help you understand: http://jsfiddle.net/user/relly/fiddles/

like image 85
Tome Pejoski Avatar answered Sep 19 '22 20:09

Tome Pejoski


Basically all data used to display the grid is stored in gridApi which enables you to manipulate the grid properties and content in your script.

onRegisterApi is used to handle events. For example: If an edit is made, or a row is selected, you would use the onRegisterApi to catch the event and run some function.

As for ordering, it doesn't matter if your gridOptions are created first, or the html DOM element. What is important is that when you initialize your grid, the variables you use in the gridOptions (eg: data) are initialized before the gridOptions.

Hope this helps

like image 21
David H. Avatar answered Sep 19 '22 20:09

David H.