Create Grid using newElement

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
pjshuey
Experienced User
Posts: 119
Joined: Wed May 25, 2016 11:58 am
First Name: Patti
Last Name: Shuey
Company Name: Conestoga Wood Specialties
Phone: 7174452886
Address 1: 645 Reading Road
City: East Earl
State / Province: Pennsylvania
Zip / Postal Code: 17519
Country: United States
Contact:

Create Grid using newElement

Post by pjshuey »

Is it possible to create a grid using the newElement API?
User avatar
matt.denninghoff
Profound Logic Staff Member
Posts: 115
Joined: Wed Feb 10, 2016 3:53 pm
First Name: Matthew
Last Name: Denninghoff
Company Name: Profound Logic Software
State / Province: Ohio
Country: United States
Contact:

Re: Create Grid using newElement

Post by matt.denninghoff »

It is not possible to create a grid this way. The grid is a collection of dozens to hundreds of Document Object Model (DOM) elements.
newElement() creates an HTML DOM element and attaches it to the Rich Display or Genie "container", which is just an element in the DOM tree.
pjshuey
Experienced User
Posts: 119
Joined: Wed May 25, 2016 11:58 am
First Name: Patti
Last Name: Shuey
Company Name: Conestoga Wood Specialties
Phone: 7174452886
Address 1: 645 Reading Road
City: East Earl
State / Province: Pennsylvania
Zip / Postal Code: 17519
Country: United States
Contact:

Re: Create Grid using newElement

Post by pjshuey »

Would it be crazy to try to create a custom widget for a grid but do it from scratch rather than based off of another grid widget?
pjshuey
Experienced User
Posts: 119
Joined: Wed May 25, 2016 11:58 am
First Name: Patti
Last Name: Shuey
Company Name: Conestoga Wood Specialties
Phone: 7174452886
Address 1: 645 Reading Road
City: East Earl
State / Province: Pennsylvania
Zip / Postal Code: 17519
Country: United States
Contact:

Re: Create Grid using newElement

Post by pjshuey »

What I would really like to do is to put a new grid on the screen on conversion from green screen to rich display. Is that possible?
User avatar
Glenn
Profound Logic Staff Member
Posts: 124
Joined: Mon Apr 14, 2014 4:08 pm
First Name: Glenn
Last Name: Hopwood
Company Name: Profound Logic Software
State / Province: Ohio
Country: United States
Contact:

Re: Create Grid using newElement

Post by Glenn »

It may be possible.

Can you tell us what you are trying to do? It may be simpler/cleaner to use a different widget to accomplish what you are trying to do.

Glenn
pjshuey
Experienced User
Posts: 119
Joined: Wed May 25, 2016 11:58 am
First Name: Patti
Last Name: Shuey
Company Name: Conestoga Wood Specialties
Phone: 7174452886
Address 1: 645 Reading Road
City: East Earl
State / Province: Pennsylvania
Zip / Postal Code: 17519
Country: United States
Contact:

Re: Create Grid using newElement

Post by pjshuey »

We are trying to show the environment (current library) that the user is in on the screen. I created a custom widget that is based on the grid widget and set the defaults on the widget so it would be database driven and query QSYS2/LIBLIST to get the library list..... We can drag this widget onto the designer screen and it works great. I would like that to be created on conversion so we don't have to remember to add it on each screen we convert. There may be a much better way to do this, but this is what I came up with. Do you have any ideas?
User avatar
Glenn
Profound Logic Staff Member
Posts: 124
Joined: Mon Apr 14, 2014 4:08 pm
First Name: Glenn
Last Name: Hopwood
Company Name: Profound Logic Software
State / Province: Ohio
Country: United States
Contact:

Re: Create Grid using newElement

Post by Glenn »

I just did a quick test and the following code in the "add enhancements" hook of the conversion theme seems to work (I didn't compile or run the screen). Note that you will need to come up with some way to get a unique value for both the "id" and "record format name" properties. Perhaps a combination of the record format name and "SFL" (must be 10 characters or less)?

Code: Select all

    var envGrid = new Object;
    envGrid["id"] = ""; // should be unique at the display file level - can be the same as the "record format name" below
    envGrid["record format name"] = ""; // MUST be unique at the display file level.
    envGrid["field type"] = "grid";
    // Repeat the envGrid[] statement for each property you want set
    format.items.push(envGrid);
Glenn
pjshuey
Experienced User
Posts: 119
Joined: Wed May 25, 2016 11:58 am
First Name: Patti
Last Name: Shuey
Company Name: Conestoga Wood Specialties
Phone: 7174452886
Address 1: 645 Reading Road
City: East Earl
State / Province: Pennsylvania
Zip / Postal Code: 17519
Country: United States
Contact:

Re: Create Grid using newElement

Post by pjshuey »

Thanks so much Glenn! I knew there had to be a way!
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Create Grid using newElement

Post by Scott Klement »

Hmmm... well, it actually _is_ possible to create a grid with "newElement". But, you would not be able to create a database-driven grid because of security concerns.

Its important to understand that newElement() is designed to create screen elements "on-the-fly" from JavaScript. So it does not create the element when your conversion script runs, but instead, creates the element when your screen is displayed. The "add enhancements" feature that Glenn described is the proper way to add elements during the conversion script.

newElement() creates the elements when the screen is displayed to the user, and it is possible to create a grid at that time. But database-driven data cannot be supplied because we don't want users to be able to use the JavaScript console to run any arbitrary SQL statement at any time. That would be a big security problem if people could do that... and if you could create a grid on-the-fly with database-driven properties, it would indeed allow them to run any SQL statement from the console.

So SQL statements for database-driven grids MUST be coded in the visual designer and saved (...and compiled) into displays on your IBM i. Otherwise the database-driven properties will be ignored.

I won't take the time to show you how to do it, here... since Glenn's solution will work much better for you. ;-) But, I wanted readers of this forum to know that it is, indeed, possible to create grids on-the-fly as long as they are not database-driven.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests