Overriding GridLinker Component Settings


Overriding settings a GridLinker component at run-time is not as simple as it is for a grid or dialog component. This is because a lot of the code that executes is hidden inside the definition of the GridLinker component. Nevertheless, once you understand more about what goes on inside the GridLinker component, it is not hard to do. The first step is to make sure you know what the aliases are for each of the grid components in the GridLinker. To find the names of the aliases:

  1. Edit the GridLinker.

  2. Display the Select & Link tab.

  3. Click the Edit button. A dialog will open telling you what the alias is for each component in the GridLinker.

For example, let's look at the sample Orders_wItems GridLinker component that is part of the sample web application that ships with Alpha Five. This component links the OrderHeader and InvoiceItems grid components. In this case the internal alias names used for each component is the same as the component name, but it need not be. Let's assume that at run-time we want to change the OrderHeader component so that it only displays 3 rows of data. If you look at the code in the .A5W page that runs the Orders_wItems component, you will see code that looks like this:

Delete Tmpl
DIM Tmpl as P
tmpl = a5w_load_component("Orders_wItems")

After the component has been loaded, the pointer variable Tmpl contains the definition of the GridLinker. This pointer variable has an internal property array called Grid_Info that contains information about each of the linked grids. This property array has a property called OverrideSettings which contains the Xbasic necessary to override settings for any grid in the GridLinker. So, for example, if the GridLinker links 4 different grid components, the Tmpl pointer variable will have a sub-array with four entries - one for each grid. The problem is that you don't know which entry in the array corresponds to which grid, so you have to execute some Xbasic to find the appropriate entry in the array. The following example show how this can be done:

dim indx as N
'find the entry in the tmpl.grid_info[] array for the component with the alias 'OrderHeader'
indx = tmpl.grid_info.find(ut("orderheader"), "ut(componentalias)")
'if (indx > 0) then a match was found
if (indx > 0) then
    with tmpl
        with Grid_Info[1]
            .OverrideSettings = <<%code%
rows = 3
        end with
    end with
end if

Place this code immediately after the code that loads the component: i.e. after this line:

tmpl = a5w_load_component("Orders_wItems")