Re: external javascript and grid.object
You can't use {grid.componentName} in the external JS file for a very good reason -- it is NOT valid Javascipt.
If you were to write some Javascript code (outside of an a5 Grid) that had '{grid.componentName}' in it, and then tried to run code you would get a javascript error.
That's because the { } syntax is how Javascript defines a JSON object, and 'grid.componentname' is NOT a Javascript object.
The reason that when you use {grid.componentName} in an A5 grid, it just works, is that A5 replaces {grid.componentName} (which to A5 is just a placeholder) with the real object name. This replacement is done on the server BEFORE any code is sent to the browser.
So, for example, if your grid alias is FOOBAR then {grid.componentname} is replaced with FOOBAR_GridObj (which is the object name of the Grid)
When you load Javascript from an external file, A5 does NOT pre-process this file before it is loaded into memory and look for placeholders to replace with real object names. it simply loads the javascript file.
And if this file has {grid.componentname} it will fail to parse, for the reasons explained above.
Here is what you could do:
in the external file, instead of using placeholders for the object name you could try something like this:
Then in the onGridRenderComplete client side event, you would add code like this:
So, what's going on here is that the linked Javascript file does NOT use any placeholders. It references a global variable to get the name of the Grid object. this global variable is set in the onGridRenderComplete event.
Originally posted by Steve Wood
View Post
You can't use {grid.componentName} in the external JS file for a very good reason -- it is NOT valid Javascipt.
If you were to write some Javascript code (outside of an a5 Grid) that had '{grid.componentName}' in it, and then tried to run code you would get a javascript error.
That's because the { } syntax is how Javascript defines a JSON object, and 'grid.componentname' is NOT a Javascript object.
The reason that when you use {grid.componentName} in an A5 grid, it just works, is that A5 replaces {grid.componentName} (which to A5 is just a placeholder) with the real object name. This replacement is done on the server BEFORE any code is sent to the browser.
So, for example, if your grid alias is FOOBAR then {grid.componentname} is replaced with FOOBAR_GridObj (which is the object name of the Grid)
When you load Javascript from an external file, A5 does NOT pre-process this file before it is loaded into memory and look for placeholders to replace with real object names. it simply loads the javascript file.
And if this file has {grid.componentname} it will fail to parse, for the reasons explained above.
Here is what you could do:
in the external file, instead of using placeholders for the object name you could try something like this:
Code:
function next() { var gridObjName = window['MyGridObjectName']; var gridObj = window[gridObjName + '_GridObj']; gridObj.pageNavigate('next'); }
Code:
window['MyGridObjectName'] = '{grid.componentname}'
Comment