Alpha DevCon Engineering Roundtables
Results 1 to 10 of 10

Thread: OnGridInitialize

  1. #1
    Member
    Real Name
    John Berry
    Join Date
    Nov 2007
    Location
    Maryland, USA
    Posts
    574

    Default OnGridInitialize

    Hello,

    I have code in the OnGridInitialize to hide certain columns based on certain conditions:

    e.tmpl.field_info[3].Column.Hide = .t.
    e.tmpl.field_info[7].Column.Hide = .t.
    e.tmpl.flagMustRecalculateGridLayoutAndControls = .t.
    .....

    but is there a way I can use the field name instead of the column number? If I add/remove fields from the grid then that code isn't going to work. It would be better if I could do something like:

    e.tmpl.field_info"LastName".Column.Hide = .t.
    e.tmpl.field_info"FirstName".Column.Hide = .t.

    Any help is appreciated.

    Thanks

    -John

  2. #2
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,101

    Default Re: OnGridInitialize

    here is something for you to try:
    Code:
            dim controlID as n
    	controlID = e.tmpl.field_info.find("id","fieldname")
    
            dim controlLastName as n
    	controlLastName = e.tmpl.field_info.find("lastname","fieldname")
    
            e.tmpl.field_info[controlID].Column.Hide = .t.
    	e.tmpl.field_info[controlLastName].Column.Hide = .t.
            e.tmpl.flagMustRecalculateGridLayoutAndControls = .t.
    and so on so forth.
    see if this works for you
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  3. #3
    Member
    Real Name
    John Berry
    Join Date
    Nov 2007
    Location
    Maryland, USA
    Posts
    574

    Default Re: OnGridInitialize

    Hi Gandhi,

    Thanks for replying. I tried your suggestion but I must be doing something wrong because I just can't seem to get it to work, however, your suggestion pointed me into a similar direction and I used a loop to loop through the fields and it works. IE:

    x = e.tmpl.fields
    for k = 1 to x
    if e.tmpl.field_info[k].fieldname = "Y1_P1_Actual" then
    e.tmpl.field_info[k].Column.Hide = .t.
    end if
    next k

    Thanks for your help.

    -John

  4. #4
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,101

    Default Re: OnGridInitialize

    why it did not work, it work fine here in version 11?
    secondly, in your loop you are verifying a single value, it looks like that to me. is that you wanted?
    your example showed you are hiding two different fields.
    you want me to post a video show it works or you are okay with what you have?
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  5. #5
    Member
    Real Name
    John Berry
    Join Date
    Nov 2007
    Location
    Maryland, USA
    Posts
    574

    Default Re: OnGridInitialize

    Hi Gandhi,

    Yes, in the loop example I was only verifying one value, in reality I'll be verifying many values; I just tried to narrow it down for the brevity sake.

    If it's not too much trouble then yes, I'd love a video.

    Appreciate your help.

    -John

  6. #6
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,101

    Default Re: OnGridInitialize

    okay here is a simple example.
    https://www.screencast.com/t/kWK6EPCs7t
    post back if you need something else.
    look for documentation array.find() which is what i utilized, sine tmpl field info is an array. click on the xbasic below the grid you will understand.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  7. #7
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,101

    Default Re: OnGridInitialize

    you said something about some conditions met, may be that needs to be addressed.
    let me know what that is, so i know.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  8. #8
    Member
    Real Name
    John Berry
    Join Date
    Nov 2007
    Location
    Maryland, USA
    Posts
    574

    Default Re: OnGridInitialize

    Hi Gandhi,

    Thanks, I understand it now. The reason it didn't work for me the first time is because I misunderstood this piece: controlID = e.tmpl.field_info.find("id","fieldname") I thought you wanted me to replace "fieldname" with the name I was looking for! Hence it didn't work. I went to the help to find out what I needed to do but in the help when I typed in array.find I get

    References > Methods > ARRAY.FIND Method
    Object moved to here.

    References > Methods > ARRAY.FIND Method
    Send Feedback on This Topic
    Add note


    and not the help screen you were looking at in the video. Clicking the link only brought up an error message so that's when I decided to use a loop instead.

    Anyway, really, thanks for spending time on this. I'll let you know how it goes.

    Thanks

    -John

  9. #9
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,101

    Default Re: OnGridInitialize

    okay
    two things:
    click on documentation on the top and will get you to where i was in the video.
    the field name ids the property and the value is id or lastname or firstname or whatever.
    so you are looking array find("id", "fieldname") will give you the element of the array where id is located like array[1].fieldname = id
    same with last name
    array.find("lastname", "fieldname") will give you array element where the fieldname is lastname like array[2].fieldname = lastname
    you are identifying the element value then using that again to hide.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  10. #10
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,101

    Default Re: OnGridInitialize

    Last edited by GGandhi; 08-06-2017 at 06:10 AM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

Similar Threads

  1. how to get variable in onGridInitialize event?
    By jennygong in forum Application Server Version 11 - Web/Browser Applications
    Replies: 5
    Last Post: 01-29-2014, 12:48 PM
  2. onGridinitialize emit javascript?
    By Catalin in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 11-28-2013, 04:11 PM
  3. OnGridInitialize dbf filter conundrum
    By Peter.Greulich in forum Application Server Version 10 - Web/Browser Applications
    Replies: 7
    Last Post: 10-15-2013, 05:28 PM
  4. Can I force OnGridInitialize to fire ?
    By Ezslim in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 02-19-2011, 09:30 PM
  5. OnGridInitialize Question
    By envisionsolutions in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 03-31-2010, 01:17 PM

Posting Permissions

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