4D View Pro: New Commands to Manage Rows & columns

Spreadsheets are great versatile tools. From dashboards to input/output UI, spreadsheets provided by 4D View Pro can quickly solve a lot of situations encountered by your end-users.

We previously explained using the 4D View Pro table feature to display and modify data collections. Using 4D View Pro tables, you may need to add or remove columns later on, depending on end-users needs. To do so, from 4D v19 R7, 4D View Pro has several new commands to manage your table columns and rows. Let’s see how it works.

HDI table management

 

The first step before adding or removing some columns is to create a 4D View Pro table. For the examples below, we’ll use a 4D View Pro table that displays some data from a database table named “People”:

$context:=New object
$context.people:=ds.People.all().toCollection()

VP SET DATA CONTEXT("ViewProArea"; $context)

$parameter:=New object
$parameter.tableColumns:=New collection
$parameter.tableColumns.push(New object("name"; "Phone"; "dataField"; "Phone"))
$parameter.tableColumns.push(New object("name"; "Email"; "dataField"; "email"))
$parameter.tableColumns.push(New object("name"; "Country"; "dataField"; "Country"))

VP CREATE TABLE(VP Cells("ViewProArea"; 2; 1; 3; 1); "PeopleTable"; "people"; $parameter)

Insert columns in a table

The VP INSERT TABLE COLUMNS command allows you to insert a column whenever you need it in your table. For example, if you want to display 2 new columns before the first column of the 4D View Pro table :

VP INSERT TABLE COLUMNS("ViewProArea"; "PeopleTable"; 0; 2;vk table insert before)
// 0 indicate the first column of the table.

 

blank

2 empty columns are now added to the table. So now we’ll fill them with the Firstname and Lastname fields thanks to the VP SET TABLE COLUMN ATTRIBUTES:

$param:=New object
// Bind the column to the Firstname field from the datacontext
$param.dataField:="Firstname"
// Change the default name of the column to "First name"
$param.name:="First name"
VP SET TABLE COLUMN ATTRIBUTES("ViewProArea"; "PeopleTable"; 0; $param)

$param:=New object
// Bind the column to the Lastname field from the datacontext
$param.dataField:="Lastname"
// Change the default name of the column to "Last name"
$param.name:="Last name"
VP SET TABLE COLUMN ATTRIBUTES("ViewProArea"; "PeopleTable"; 1; $param)

blank

Insert and remove rows

In the same way, you can use the VP INSERT TABLE ROWS command to insert empty rows in your table:

VP INSERT TABLE ROWS("ViewProArea"; "PeopleTable"; 1; 2)

blank

Remember that VP INSERT TABLE ROWS doesn’t just add graphical elements like VP INSERT TABLE COLUMNS. When VP INSERT TABLE COLUMNS adds just columns in the sheet, VP INSERT TABLE ROWS adds rows in the sheet and creates 2 new rows in the collection of your data context.

In our example, if you use VP Get data context, you obtain your people collection with 2 new empty lines, people[1] and people[2]:

$data:=VP Get data context("ViewProArea")

blank

And if you write some information in your empty cells:

blank

The attributes corresponding to your new information are automatically added. Here, people[1] have been filled with details:

$data:=VP Get data context("ViewProArea")

blank

If your remove some rows, it works in the same way. For example, if you remove all but the first 2 rows, the rows will disappear graphically and in the datacontext:

VP REMOVE TABLE ROWS("ViewProArea"; "contexttest"; 2; 10)

blank

$data:=VP Get data context("ViewProArea")

blank

So the association between datacontext and table is an easy way to manage your collections in 4D View Pro!

Check out this feature with the HDI above and the documentation for more details!

Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.