The fastest easiest way to get it right.

Responding to Grid Mouseclicks

You may want to have a grid displayed with data in it, and then perform some action when the user clicks on a row. This can be done with Javascript and by using Andromeda's event dispatcher system.

It works like this. When a user clicks on a row in a grid, an event is sent to the Andromeda event dispatcher. If you have an object that responds to that event then you can do anything you want when the user clicks on a row.

We will start out with our example of a song playlist:

class x6example extends androX6 {
    function x6main() {
        # Always begin with this:
        $top = html('div');
        #  ...other html is added here...
        # Now for the grid create command.  The parameters are:
        # 1) Height
        # 2) Table we are editing
        # 3) Flag for lookup textboxes, no in this case
        # 4) Flag for sortable.  No
        # 5) Flag for buttonbar, No, not editable
        # 6) Flag for editable, no
        $grid = $top->addGrid(hSize(300),'states','N','N','N','N');
        # Now add a single column, take it from the
        # data dictinoary, that is always easiest
        $dd = ddTable('songs');
        # Now pull the data and add it.  Note that we
        # pull the 'skey' column so the grid has a
        # unique ID for each row.
        $view = ddtable('songs');
        $sq="select skey,songname from $view";
        $rows = SQL_AllRows($sq);
        # Create an invisible div object, we will see 
        # what to do with this below
        $listener = $top->h('div');
        $listener->hp['id'] = 'song_listener';
        $listener->hp['style'] = 'display: none';
        # ...and this is always at the end

The Event

When the user clicks on a row, the grid will fire an event with the name "reqEditRow_songs". This event is named "reqEditRow_" plus the name of the table that the grid is displaying. The event fires with a parameter, which is the skey value of the row.

To respond to this event, we will send up an object to the page that is listening for it. To do this, we put a method into our "x6example" class called x6script(). Anything we put into the x6script() routine will be executed when the document has loaded.

class x6example extends androX6 {
    function x6main() {
        # This code skipped for brevity, paste in the
        # code from the above example.
    function x6script() {

comments powered by Disqus
Home |  Documentation |  Download |  Credits |  Contact |  Login
Andromeda © Copyright 2004-2013, Licensed under the GPL Version 2