Alpha Video Training
Results 1 to 16 of 16

Thread: How to add a linked child grid to the Detail View of a grid?

  1. #1
    "Certified" Alphaholic
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    1,065

    Default How to add a linked child grid to the Detail View of a grid?

    Hi folks
    I have a grid setup with a detail view set as "popup window". In the popup detail view, i would like to enter a child grid, how can i accomplish that?

    Thanks in advance
    Jaime

  2. #2
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    512

    Default Re: How to add a linked child grid to the Detail View of a grid?

    There's a video out there somewhere on how to do this, but I can't find it.
    So you'll need to do a few things. First add a 'Static Text' to the DV. Edit the text to be
    Code:
    <div id="child-grid"></div>
    Then add a button below or above it. The button's onClick event needs to Open a grid component. Here's the important part, in the Target setting change it to DIV and change Target DIV ID to child-grid. (I also turn off 'Can hide target DIV?'). Stop here and test your child grid. It should open when you click the button inline where the static text was put. Now that that is working, go to the 'onDetailViewRender' Client-side event and put this code
    Code:
    ele = $('{grid.componentName}.D.V.R1._UNBOUND_BUTTON_1');
    if(typeof ele != "undefined") ele.click();
    That will open the child grid up automatically when you open the DV. (Change the button number accordingly for more than one child-grid.

    EDIT: Hot tip here! I also put the following code on my button after the grid open to totally remove the button after it's been clicked. (requires jQuery)
    Code:
    jQuery(this).parent().parent().remove();

  3. #3
    "Certified" Alphaholic
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    1,065

    Default Re: How to add a linked child grid to the Detail View of a grid?

    Dear Sparticuz
    This not only works as advertised, it also teaches me a few tricks!
    A million thanks!!!

    Jaime

  4. #4
    "Certified" Alphaholic
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    1,065

    Default Re: How to add a linked child grid to the Detail View of a grid?

    Just a small problem now, how can i align the grid completely to the left ( exactly as the labels? ) I see the leftmost part of the grid has an indent to the right...
    See attached picture
    LinkedGridPos.JPG

    Thanks
    Jaime

  5. #5
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    512

    Default Re: How to add a linked child grid to the Detail View of a grid?

    I haven't tried, but you could probably put 'display:none' in the Heading in-line style for the Static Text field.

  6. #6
    "Certified" Alphaholic
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    1,065

    Default Re: How to add a linked child grid to the Detail View of a grid?

    Yup, that did the trick! It messed up the position of the 2 fields that came before, but i fixed it by wrapping those fields in a frame...
    Many thanks for your help
    Jaime

  7. #7
    Member
    Real Name
    Vaughn Seward
    Join Date
    May 2010
    Posts
    184

    Default Re: How to add a linked child grid to the Detail View of a grid?

    Quote Originally Posted by Sparticuz View Post

    EDIT: Hot tip here! I also put the following code on my button after the grid open to totally remove the button after it's been clicked. (requires jQuery)
    Code:
    jQuery(this).parent().parent().remove();
    This works great... another way to hide the button is to use '1=2' in the hide/show property of the button.

  8. #8
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    512

    Default Re: How to add a linked child grid to the Detail View of a grid?

    That's a more 'Alpha-friendly' way, but I prefer the jQuery method because it removes the whole row and doesn't have any spacing issues.

  9. #9
    Member
    Real Name
    Vaughn Seward
    Join Date
    May 2010
    Posts
    184

    Default Re: How to add a linked child grid to the Detail View of a grid?

    That makes sense.

    BTW there is one oddity with this technique that I ran into when I tried it yesterday... First some context: it is A5 v10 SQL/Server web app, the linked-to grid is linked via an SQL identity key. The technique works fine in update mode. But if you tell Alpha to not close down after a new record is inserted, then instead of the linked-to grid showing no records like it should after an insert of the parent grid, it appears with a list of records, presumably based on the linking key of the last record in the grid before the Add button was clicked. Alpha is obviously getting confused.

    I wonder if somehow using a GUID instead of an identity key might help this situation?

  10. #10
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    512

    Default Re: How to add a linked child grid to the Detail View of a grid?

    If I understand you correctly, I have that problem as well, I just haven't tackled it yet. So basically what is happening when you are inserting a new parent record there is NO primary key for it yet. (Obviously, because there is no record yet). This presents a problem when the child grid rows contain the parent primary key (which doesn't exist). Using a guid would fix this problem and I'll explain that after the Auto-increment solution.

    I've been thinking about this for a while. Here is my proposed solution. (I haven't tested or implemented this in my own code yet)
    • Server-side Event's OnInitialValueCalculate:
      This event fires before the New Record rows are displayed. It allows you to compute initial values for fields in the Grid.
      We basically want to get the SQL server's NEXT primary key using something like this
      Code:
      show table status like '{table_name}';
    • This will return a column called 'Auto_increment' which will be the value of the NEXT auto_increment pk.
    • Then we run
      Code:
      e.newValues.id = auto_increment_value
      and we probably also want to set this as a page/session variable.
    • On the child grid, I'm not sure what happens, hah. I'm thinking that the linked key should detect the value we've already inserted in the id field and adjust accordingly, if so, we're gold with that solution. It should now allow you to insert child records WITHOUT the parent record already existing. If that doesn't work, then you would just need to set it again from the page/session variable.


    There are some problems with the above 'pseudo-code'. The main problem being we're not 100% sure the next pk identity will be that auto_increment value. We could get the pk next ai value, fill out our record, someone else inserts a record before we're done (stealing our pk), then saving our record would fail because they took our pk. So this approach is pretty much useless in a concurrent environment.

    Thinking about this, GUID's would be alot easier. The reason being is because of the 'non-existent' chance of pk collision. The steps would basically be the same as the above steps, except instead of querying the sql server for the next primary key, we would create the pk ourselves. By running a xbasic function that creates a new guid. I know it exists, but I can't find the wiki page, hah! Then just use the new guid in the OnInitialValueCalculate. The BIG plus of using a guid is that if someone else inserts in that table while you are still working, they would have gotten a different guid, again, because of the 'non-existent' chance of a collision.

  11. #11
    Member
    Real Name
    Vaughn Seward
    Join Date
    May 2010
    Posts
    184

    Default Re: How to add a linked child grid to the Detail View of a grid?

    With the GUID approach, you suggest creating it via an xbasic function. Could this also be done with Javascript and the pk initialized in the AfterDetailViewNewRecord client event?

  12. #12
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    512

    Default Re: How to add a linked child grid to the Detail View of a grid?

    I would assume it could be done there as well. http://stackoverflow.com/questions/1...-in-javascript

  13. #13
    Member
    Real Name
    Vaughn Seward
    Join Date
    May 2010
    Posts
    184

    Default Re: How to add a linked child grid to the Detail View of a grid?

    Thanks, I saw that and was wondering, as one comment was: "However, note in the comments that such values are not genuine GUIDs. There's no way to generate real GUIDs in Javascript, because they depend on properties of the local computer that browsers do not expose."

    Yet someone else says, "Actually, the RFC allows for UUIDs that are created from random numbers. You just have to twiddle a couple of bits to identify it as such."

    But of course, I just realized probably the best way is to simply create it in SQL (as the initial for the column using the NEWID() function):

    http://www.dailycoding.com/Posts/gen...ql_server.aspx

  14. #14
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    512

    Default Re: How to add a linked child grid to the Detail View of a grid?

    I'm not terribly familiar with uuid's but from what I know, the rate of collision is so low it's practically impossible. I wouldn't worry about 'genuine' guid's, just follow the rfc standard.

  15. #15
    Member
    Real Name
    Vaughn Seward
    Join Date
    May 2010
    Posts
    184

    Default Re: How to add a linked child grid to the Detail View of a grid?

    Update:

    I had a closer look at what was going on and found that your technique does actually work after an Add. What I discovered was that I had some bad data in the child grid's main table. When I cleaned that up it started working as expected. So there is probably no reason to resort to GUID's.

    BTW, if you do need to use GUIDs*, I found you can do this:

    -In the CanInsertRecord server event, use the Xbasic function api_uuidcreate() to initialize the GUID key.

    *To create a table with a GUID, you can do this:

    -Define the column as varchar(36), and set it to be the primary key.
    -Set the default to newid(), if you aren't setting it in Xbasic.

  16. #16
    Member
    Real Name
    Vaughn Seward
    Join Date
    May 2010
    Posts
    184

    Default Re: How to add a linked child grid to the Detail View of a grid?

    Oops. I think I spoke too soon. It seems to work when you first click the Add button (no records fill the sub-grid); however, after filling in all fields and Saving, it is pulling up records from apparently the last record highlighted. An A5 bug after all.

    Work-around: change the detail view to close after editing. This way A5 doesn't get a chance to display the wrong records.
    Last edited by cFlat7; 11-07-2011 at 06:58 PM.

Similar Threads

  1. Linked grid in detail view
    By eskimoavenue in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 01-16-2011, 05:42 AM
  2. Image - Add/Update in Grid/Detail View
    By markmoss in forum Application Server Version 10 - Web/Browser Applications
    Replies: 3
    Last Post: 08-04-2010, 10:21 AM
  3. Update Field on a detail view from a linked grid
    By jacsolutions in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 06-23-2010, 07:22 PM
  4. Grid with Detail View and Linked
    By Turnbullca in forum Application Server Version 10 - Web/Browser Applications
    Replies: 11
    Last Post: 11-25-2009, 04:54 PM
  5. Grid View with Detail View To Add New Records
    By Jeff Benson in forum Web Application Server v7
    Replies: 2
    Last Post: 05-26-2006, 11:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •