Create Servoy Extra Table dynamically

Forum to discuss the new web client version of Servoy.

Create Servoy Extra Table dynamically

Postby dev-ws-011 » Thu Jul 01, 2021 2:36 pm

Hi All,

I am working in NG Desktop client and need to create Servoy Extra Table web component dynamically.

Any help will be highly appreciated.

Regards
Servoy Developer
dev-ws-011
 
Posts: 73
Joined: Fri Oct 21, 2016 8:23 am

Re: Create Servoy Extra Table dynamically

Postby rph » Thu Jul 01, 2021 5:57 pm

Hi

Create a form and put an empty table component on that and give this component a name (in my example "meinetabelle") so you can reference this. Of course you can even do this with SolutionModel.

Then, in the onLoad-Event, you can put something like this:

Code: Select all
function onLoad(event) {
   
   var meineTabelle = elements.meinetabelle; // Look for the "table"-component
   
   meineTabelle.addStyleClass("mycss"); // set the style class of my table with the api
   
   var datumFeld = meineTabelle.newColumn("datum_vorgaenge"); // create a new column with dataprovider "datum_vorgaenge"; return a "column"-object
   
   // Set the different properties for the column
   datumFeld.headerText = "Vorgangsdatum";
   datumFeld.width = 250;
   datumFeld.format = "dd.MM.yyyy";
   
   // more columns to come...
}


Also have a look here: https://github.com/Servoy/servoy-extra- ... wiki/Table

Hope this gives you an idea.

Best
Roland
rph
 
Posts: 75
Joined: Wed Aug 10, 2011 11:44 am
Location: Cham, Switzerland

Re: Create Servoy Extra Table dynamically

Postby dev-ws-011 » Fri Jul 02, 2021 8:45 am

Thanks for you response.

If we need to create table completely from code, then how to achieve this?

As I have tried following code but its not working.
Code: Select all
var detailForm = solutionModel.getForm("test2");
var table = detailForm.newWebComponent('table1','servoyextra-table');


Any help will be highly appreciated.

Regards
Servoy Developer
dev-ws-011
 
Posts: 73
Joined: Fri Oct 21, 2016 8:23 am

Re: Create Servoy Extra Table dynamically

Postby paronne » Fri Jul 02, 2021 9:04 am

Hi,

if you create the table with solutionModel. You can use the setJSONProperty("columns", myArrayOfColumns);


Code: Select all
         
var columns = [];

/** @type {CustomType<servoyextra-table.column>} */
var column = {};
column.dataprovider = "productid"
column.headerText = "Product"
column.valuelist = "products"
columns.push(column);
table.setJSONProperty('columns',columns);


Regards,
Paolo
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: Create Servoy Extra Table dynamically

Postby dev-ws-011 » Fri Jul 02, 2021 12:06 pm

paronne wrote:Hi,

if you create the table with solutionModel. You can use the setJSONProperty("columns", myArrayOfColumns);


Code: Select all
         
var columns = [];

/** @type {CustomType<servoyextra-table.column>} */
var column = {};
column.dataprovider = "productid"
column.headerText = "Product"
column.valuelist = "products"
columns.push(column);
table.setJSONProperty('columns',columns);


Regards,
Paolo


Thanks Paolo for your response. It worked for me.

Roland, I appreciate your efforts too.

Marking this thread as RESOLVED.

Regards
Servoy Developer
dev-ws-011
 
Posts: 73
Joined: Fri Oct 21, 2016 8:23 am


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 9 guests