Forums

Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum How can I add new datagrid object to remote form?

  • How can I add new datagrid object to remote form?

    Posted by khanh vu on August 25, 2023 at 4:17 am

    I read this “<b style=”background-color: var(–bb-content-background-color); font-family: inherit; font-size: inherit; color: var(–bb-body-text-color);”>Adding Objects to JavaScript Forms

    You can add a new object to a remote form instance or a Paged Pane in the form at runtime using the $add() method. Note that you cannot create an entirely new object using this method, rather the $add() method in this context lets you copy an existing object in the form and add it to the form or pane. The following method can be used, where $cinst is the remote form instance:

    $cinst.$objs.$add(

    cName,rSrcItem[,rParentPagedPane,iPageNumber,bAllPanes=kFalse])

    adds new object cName to the JavaScript remote form instance by copying rSrcItem (existing object in same instance). The default action is that the new object is added to the form (when rParentPagedPane etc are omitted), otherwise you can specify the Paged Pane parameters to add the new object to a Paged Pane in the remote form.

    This method can only be used in server methods, not a client-side method, that is, the information about methods etc is not present on the client. There is a logical limit of 16384 controls on a remote form, although performance will be impaired well before that limit.

    The rSrcItem and rParentPagedPane parameters must both be item references to objects in the same remote form instance: their original properties and methods defined in the class when the form was instantiated will be the initial properties and methods of the new object.

    If the object to be copied (rSrcItem) is a paged pane, then its children are not copied.

    This method of copying objects cannot be used to copy complex grids. Furthermore, complex grids cannot be anywhere in the parent hierarchy.

    Note that you cannot use the $remove() method to remove objects you have added using the $add() method: to remove or hide such an object, you can set $visible for the object to kFalse. In addition, you should note that $order is not assignable at runtime so you cannot add a new object and then change its field order.”

    But, I cannot do it. anyone can help me ?

    khanh vu replied 5 months, 2 weeks ago 2 Members · 4 Replies
  • 4 Replies
  • Andreas Pfeiffer

    Administrator
    August 30, 2023 at 1:56 pm

    Hi Khanh,

    with this technique you can copy objects in a remote form.

    However the question is if this is a good approach. Designing the remote form by adding objects dynamically will be slow and is not using the remote form class as it has been designed. The class is a kind of a database record that is holding its fields. The whole library is the database that holds the UI and the functions.

    If you still need an example how to copy objects in a remote form let me know. I will send some code how to achieve this. I am just afraid that Omnis is then kind of misused by storing the field information somewhere else. I have seen this in other projects which makes things unnecessary complex.

    Best,

    Andreas

  • khanh vu

    Member
    August 31, 2023 at 2:59 am

    Thank you for your guidance, I asked this to simply enhance my understanding of Omnis.

    Best,

  • Andreas Pfeiffer

    Administrator
    August 31, 2023 at 8:43 am

    Hi Khanh,

    Again not really recommendable. However under certain circumstances it might be necessary and it is possible.

    For example you can have the following code behind a button. When the button is clicked it will generate a copy of the button:

    On evClick
    Do $cinst.$objs.$add('newButton',$cfield) Returns lNewButtonRef
    If lNewButtonRef
    Do lNewButtonRef.$top.$assign(30)
    Do lNewButtonRef.$left.$assign(250)
    Do lNewButtonRef.$text.$assign('I am new')
    End If

    Note that $cfield is the reference to the field where this code is actually located. In this case it is the button you have clicked on. You can also refer to another object by using this notation:

    $cinst.$objs.myOtherField

    “lNewButtonRef” is a local variable of type item reference. This is a pointer to the new field and can be checked with the IF statement. It can also be used to assign other properties such as $top, $left, $text etc.

    So in theory you could dynamically create your UI but then you will lose the advantage of having a graphical design tool etc. This is one of the strength of Omnis development.

    So why not simply drag the desired object from the component store onto the form?

    Best,

    Andreas

  • khanh vu

    Member
    September 5, 2023 at 6:15 am

    Thank you,

    I will remember that

Log in to reply.