Add columns to grid dynamically

Rauf

Rauf

VIP Member
Is there any way to add columns to a grid using ER. For example, I will define 'n' number of tasks for an employee in a table. So if I take the 'Custom Employee Task Entry', for each employee the defined 'n' number of tasks should come as 'n' number of columns.
This make my application more user friendly.
 
Yep....well this does rows not columns, but why not flip your display

Use system function Insert Grid Buffer Row

InsertGridBufferRow takes the grid buffer values and inserts a grid row in the specified location. After the grid row is inserted, the row will receive focus on update grid.

Parameters

Parameter
Description
I/O
Required
Notes

Grid
Specify grid to be used

Row
Specify row location for insert

Selectable?
Yes/No - With this line highlighted, does Select work?

Protected?
Yes/No - Can this line be edited?

Updateable?
Yes/No - Should the Update/Add events be executed for this row?

Deletable?
Yes/No - If this row is highlighted, does Delete work?

Clear After?
Yes/No - When the operation is complete, should the GBs be cleared of their values?
 
Danter,

Thanks for quick reply.
I am aware about this function "Insert Grid Buffer Row". But it will insert rows dynamically, not columns :)

In my "Tasks" table, the tasks will be entered row by row like

1 Task One
2 Task Two
.
.
.

So the "Custom Employee Task Entry" should come like the following,

EmployeeID Name Time-Task1 Time-Task2 ...
 
Ok, not that I am aware of

I guess you'd have to add them but then hide/show them as your logic dictates. HideGridColumn / ShowGridColumn

You can override the column to be whatever you want using SetDataDictionaryItemForGridColumn and SetDataDictionaryOverrideForGridColumn
 
Yea, but the number of tasks is dynamic. Sometimes, it may be 5 tasks, sometimes 7 or sometimes 30 etc.
 
Then you would need to cater for the maximum by adding them to the grid, and code the hide/show for that as JD suggested.
You can't insert grid columns dynamically at run time, only hide/show.
 
Hi David;
Well. It is the way.
And let me know, if we can parametrize the column name. AFAIK, it is also impossible.
For example, I will add 30 columns at design time. And if I have only 7 tasks, I want to show only the 7 tasks.
If I do a fetch to check if the task exist, then it will be 30 fetches. Then hide or show accordingly. I think, there will be horrible performance issues.

My logic is to hide another 23 columns using a loop: but we cannot parametrize the column name, it should be assigned at ER design time :(
 
No, no arrays in ER. Yes, it's painful.

Yes, doing 30 fetches on each grid row is fetched event to condition your columns will give woeful performance.
 
You don't need 30 fetches
Speed it up by hiding them all and then select/loop and display as many as you find. Have a counter to let you which record you are on.
I can't imagine you'd want to show task 9 if task 8 doesn't exist

Can't really visualise what you are doing

Or....Just show all 30 and left to right, have the found tasks on the left and then on the right default a blank in the columns you're not populating
Bit easier, no?

And yes you can change the name of a column

SetGridColumnHeading sets the grid column heading text.

Parameters

Parameter
Description
I/O
Required
Notes

Grid
Identifies the grid control
I
Y


Column

Identifies the column whose heading is to be changed



I


Y




Return Values

Return Value
Description

None
This does not return a value



See Also

SetControlText

SetFormTitle

SetDataDictionaryItem

SetDataDictionaryItemForGridColumn

SetDataDictionaryOverrides

SetDataDictionaryOverrideForGridColumn
 
Last edited:
Rauf,

There is no means to 'dynamically' add columns to a grid. Additionally, there is no means to 'dynamically' move the location of any columns within a grid.... I here you, bad news.

Last year I had a project that required the grid to be dynamic... The client wanted grid columns to display, based on different types of values. Basically - they wanted the grid to be a pivot table. I ended up adding as many columns as the client said they would ever need (plus more, because clients never know how many they need). I did not tie the 'dynamic' columns to a BSVW. As the BSVW was read, I populated the columns based on the sequence/value of the data in field... writing the values across the grid BUFFER, the writing the grid row buffer when the key values changed. Additionally - after the grid was populated, I did the Hide/Show column based on which columns had valid values.

Painful and a lot of repetitive programing that cannot take place in a NER (has to take place in the application due to App ER System Functions).

Regards

(db)
 
Anyway, I am coding with the said logic. 30 columns :(
And I will use Power Edit form to show the related tables in the same from (another subject :) )
 
Like Johndanter states - no need to do 30 fetches.

Have that 'detail' table attached to your BSVW.
Hide the Grid
As each row read, validate the Table Column and Populate a corresponding variable
When the Keys Change, flush the values of each variable to its corresponding Grid Buffer variable and write the Grid Buffer.

Would this be a good topic for Tips Traps document on the JDE Research site? More and more organizations are wanting to display data in a pivot - instead of table driven.

(db)
 
Rauf,

There is no means to 'dynamically' add columns to a grid. Additionally, there is no means to 'dynamically' move the location of any columns within a grid.... I here you, bad news.

Last year I had a project that required the grid to be dynamic... The client wanted grid columns to display, based on different types of values. Basically - they wanted the grid to be a pivot table. I ended up adding as many columns as the client said they would ever need (plus more, because clients never know how many they need). I did not tie the 'dynamic' columns to a BSVW. As the BSVW was read, I populated the columns based on the sequence/value of the data in field... writing the values across the grid BUFFER, the writing the grid row buffer when the key values changed. Additionally - after the grid was populated, I did the Hide/Show column based on which columns had valid values.

Painful and a lot of repetitive programing that cannot take place in a NER (has to take place in the application due to App ER System Functions).

Regards

(db)

Can you please explain this idea in detail?

For my last task, I created 30 columns and did 30 fetches :(

Again, I got the similar task with infinite number of columns :( :( .

Please have a look at the attachment.


My idea is to have 30 columns during the grid design. And I will implement paging for columns(same as row paging).
While page loading, I will fetch Month Seq No from 1 to 30, if the user click 'Next Columns', I will load 31 to 60.

So if the Month Seq No is 1, I need to assign the amount to grid column 1. If the Seq No is 2, then grid column 2 etc.
Also, if the Seq No is 31, I will calculate 30 mod 31 ~ 1, and will update the first column...

How is this idea ?
 

Attachments

  • Pivot Table.jpg
    Pivot Table.jpg
    132.2 KB · Views: 18
For this type of task consider using power forms.
Main form has grid for the identity / fixed Columns (Employee, etc).
Sub Forms do what John Danter suggested and flip horizontal to vertical - so that original example of Tasks would have 1 task per row with the Task attributes as columns in the row.
User selects a Employee in the Main form grid hich then causes the child form grid to populate with the "tasks" for that employee.
 
Back
Top