Results 1 to 3 of 3

Thread: [Answers] Grid-2

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] Grid-2

    Q:
    May I know if I can add a command button in a column of a grid so that user can click on it to popup a form for data entry
    A:
    The grid section is comprised of columns.
    Double click on the column header to slide in the column attributes.
    A column has a wide range of attributes including the ability to display as a "Button", a "Hyperlink" or a "Custom Control".



    Then in the Grid section attributes add your delegate for "Link Clicked".





    any grid section filters that have {...} macros in them, these are expanded at the time of refreshing the grid. This basically means that the filter itself is dynamically evaluated at the time the grid is refreshed. This works in all views; desktop, web and mobile.



    A grid is bound to data so IOW there is a corresponding cursor for each grid.
    As you navigate records in the grid the active record in the underlying cursor is changed.
    You can update the active record and then refresh that specific record in the grid using oGrid.refreshRecord( recno() )

    If the underlying cursor has been dynamically created from a virtual table query you need to specify a primary key and issue the replace statement which will generate the SQL dynamically and execute it.



    If you make the grid "readonly" it will be highlighted.
    Otherwise
    Code:
    Lianja.get("page1.section2").grid.activeRow = 0


    The grid is bound to your data which I understand to be a SQL query so you can update the data and refresh the grid (saving the activerow and positioning back on it).

    The ROWID for the base table is a hidden column that you can use to perform the update.
    Look in the console and LIST STATUS to see what cursor is bound to your grid them SELECT cursorname and issue a ? rowid. That is the record in the base table that needs updated.



    You need to use the doScroll() method like this if you want to move down the rows of the grid.
    Code:
    Lianja.get("clock_records.list").grid.doScroll( arg )
    Note that Lianja.get() does not require "page:", you are looking up the object.



    Q:
    I tried the SQL with filter as follows but the grid always show all records
    SQL :
    select * from ventlrec
    Filter :
    where clernoee="{peoplekiosk.emp_no}"
    A:
    The filter is a condition. Remove the where.
    A better way to achieve this would be to apply the whole sql select ... Where ...
    What data type is clernoee? If it's not a char column remove the quotes.



    Q:
    I have a desktop app with a page with one grid section
    I have set the "Filter" attribute to as follows for top grid section :
    clernoee="{peoplekiosk.emp_no}"
    A:
    What is "peoplekiosk"? If it is a namespace perhaps it is not declared until later.
    Setting a filter on a large number of records is also not a good idea.
    Better to have an index key on it and restrict by the index key.
    You do not say if this is a table, SQL statement or Virtual Table.
    Setting filters to variables requires the grid to be manually refreshed programmatically when you change the variable.

    If the grid is not editable use SQL statement.
    If it is editable use a Virtual Table.
    Look at the Virtual Tables example and you will see how {...} macros are used in the "where" condition of the SQL statement.



    Added the ability for a grid section to have "Multi Select Rows". This displays a checkbox column for each row. As the user clicks a checkbox, the "selectionChanged" delegate is called with a comma separated list of values. These values are determined by the "Multi Select Row Expression" e.g. You can multi select rows in a grid and then call your own business procedure to handle app specific business logic



    And these are the attributes you need to set for the grid section to enable this functionality.



    The "selectionChanged" delegate itself looks like this.

    Code:
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'selectionchanged' event
    proc page1_section2_selectionchanged(arg)
        // 'arg' is a comma separated list of items selected
        // It can be used directly to load the selected items into a ListBox
        Lianja.writeOutput("selectionChanged() arg="+arg)
    endproc


    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...ll=1#post12352
    This same topic is extended to another thread: http://www.lianja.com/community/show...Answers-Grid-1
    ...and another thread (dont ask why): http://www.lianja.com/community/show...Answers-Grid-3
    Last edited by josipradnik; 2016-10-24 at 03:26.

  2. #2
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    I have a varchar field coming from SQL Server that once it is clicked on in the grid, the data is replaced with the word memo.
    This field is defined as nvarchar(2000)
    From a data modeling perspective, what legnth or condition of a field will make it appear as "memo" in a grid?
    I am not sure if this was already discussed.
    It seems that any hex value in my grid is coming up as the word object.
    Is there a way I see the actual values in the grid?
    I also need to see the values that are showing up as Memo, since I am not using a memo field
    A:
    Anything above 255 I believe.
    Any varbinary column with be "object" as it is unknown what it contains.
    Any varchar column will be "memo". Any character fields above the 255 limit will be treated as memos.



    using the where clause on the grid seems to work very well for me.
    This way, it really is irrelevant the size of the table.

    Code:
    Lianja.get("PageName.sectionName").where = "value = 5";
    Lianja.get("PageName.sectionName").refresh();


    Q:
    how I can get a record object of the current grid active record?
    What I need to do is to allow me to programmatically change the field values of the active record using code
    A:
    You can update the active record and then refresh that specific record in the grid using oGrid.refreshRecord( recno() )
    If the underlying cursor has been dynamically created from a virtual table query you need to specify a primary key and issue the replace statement which will generate the SQL dynamically and execute it.



    You can add whatever control you want in the grid.
    In this example I create a container with a textbox and a button.

    First, create the procedure to create the container and the objects you want.
    I did this in the custom library of the page.

    Code:
    proc mycontainer
    mycontainer = createobject("container")
    mycontainer.layout = "horizontal"
    mycontainer.height = 50
    mycontainer.addobject("text1","textbox")
    mycontainer.addobject("btn1","commandbutton")
    btn1.caption ="Custom Button"
    
    return mycontainer
    Then I added a new column in the grid by right clicking the header of an existing column and selecting "Insert Column After"
    The in the attributes of the new column, I entered mycontainer in the custom control option.
    Then you can see the custom container in my grid.



    So - if you need to have a tooltip, You just add it.

    Code:
    proc mycontainer
    mycontainer = createobject("container")
    mycontainer.layout = "horizontal"
    mycontainer.height = 50
    mycontainer.addobject("text1","textbox")
    mycontainer.addobject("btn1","commandbutton")
    btn1.caption ="Custom Button"
    text1.tooltip ="this is tooltip"
    
    return mycontainer




    you have some larger field that you want to edit. For those field, use the hyperlink to bring up a dialog box for the edit. This way you have a clean edit, not in a small field, you are using a best practice and properly creating a modern application and you do not lose any functionality.

    Have a look at this example.
    I concatenated firstname, lastname and address into one field.
    If I want to edit that field, I just click on the link and bring up a dialog window.

    I accomplish everything I a looking to do in a very intuitive way without trying to re-invent the wheel.



    In the linkclick section of my page, I call the dialog window.

    Code:
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'linkclick' event
    proc page1_section1_linkclick()
    
    Lianja.showdialog("Employee Edit","pgEmployeeEdit",500,500)
    // This refreshes the grid to show the new values
    Lianja.get("section1").refresh
    endproc
    The result.



    If I was building this for web, I would call the showdialog with a parameter and an action.
    In the desktop, it is already on the record pointer.

    Try to add some custom delegate to your "text1" (methods like valid() or so...).
    That's easy.

    You create your own textbox class with a valid.
    Like this.

    Code:
    define class mytextbox as textbox
    proc valid()
    wait window "valid"
    endproc
    
    enddefine
    Then instead of adding textbox, you add mytextbox.



    Q:
    not found the property that return the number of column..
    A:
    This should work

    Code:
    oGrid = Lianja.GetElementByID("page.section").grid
    ? oGrid.ColumnCount




    Q:
    If i have filtered grid like this

    Code:
    Lianja.get("section1").grid.filter = "startsWith(customerid, 'A')"


    and I use the code below to move from record to record then it does not work.

    Code:
    sec = Lianja.get("section1")
            grd = sec.grid
    grd.goto(grd.activerow + 1)

    It appears that the row is being moved on the filtered gird but I suspect it is moving between rows that are not visible.When the grid is not filtered it works just fine:

    Code:
    Lianja.get("section1").grid.filter = ""
    sec = Lianja.get("section1")
            grd = sec.grid
    grd.goto(grd.activerow + 1)


    A:
    Try doscroll

    Code:
    Lianja.Get("page1.section1").grid.doscroll(1)

    Or

    Code:
    oGrid = Lianja.get("page1.section1").grid 
    lnActiveRow = oGrid.activerow + 1
    oGrid.activatecell(lnActiveRow, 1)

    In the second example you can specify the column.
    In the first one the first column is activated.



    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...p?2717-Answers
    This same topic is extended to another thread: http://www.lianja.com/community/show...Answers-Grid-2
    ...and another thread (dont ask why: I was young in thread editing): http://www.lianja.com/community/show...Answers-Grid-3

  3. #3
    Senior Member
    Join Date
    Nov 2014
    Location
    Kailua, Hawaii
    Posts
    104
    Wow!! Thank you Josipradnik for this super informative post.

    Steve

Bookmarks

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
  •  
Journey into the Cloud
Join us