Skip to main content
17-Peridot
July 18, 2017
Solved

Dynamic columns from Infotable

  • July 18, 2017
  • 2 replies
  • 8209 views

Hi,

I'm getting different Infotables with different count of columns. Say, table1 with 10 columns and table with 20 columns and these columns(names) are not fixed,may change frequently.

Now I want to show all the columns from all the infotable onto a single GRID.

In short,I don't have any predefined DataShape to bind.

How to achieve that?

I have tried below approach:

****************************************************

// result: INFOTABLE dataShape: RootEntityList  //Fetching Thing Names on the basis of ThingShape Name

var thingNames = ThingShapes[ThingShapeName].GetImplementingThings();


//Creating Dynamic Infotable with no Datashape

var params = {

infoTableName: "MyTable" /* STRING */

};

//result: INFOTABLE

var result = Resources["InfoTableFunctions"].CreateInfoTable(params);

//Looping to get thingName and get its Properties and adding its row in Dynamic Infotable,created above

var tableLength = thingNames.rows.length;

for (var y = 0; y < tableLength; y++)

{

var Tname = thingNames.rows.name;

    // result: INFOTABLE 

var propertyValue = Things[Tname].GetPropertyValues();

   result.AddRow(propertyValue.rows[0]);

}

****************************************************


Output: Infotable without DataShape

Mashup Bind: Grid bind to ALL DATA with "Show All Columns" option to "true".




Best answer by CarlesColl

Hi Tarun,

Just add a ""+ in front of iLF[key ].baseType :

var iLF ;// 

if ((data.dataShape==null)||(data.dataShape==undefined)) { 

   iLF = data.ToJSON().dataShape.fieldDefinitions; 

} else { 

   iLF = data.dataShape.fields; 

for (var key in iLF) { 

   result.AddField({ name: key, baseType: (""+iLF[key].baseType) }); 

}

2 replies

14-Alexandrite
July 18, 2017

Tarun Nayyar​,

Did it work with your approach? Did you have any error during running your code(please attach it if any)? Or it worked for you and you are still looking for

any better approach from the community?

Thanks,

Br,

Anna

1-Visitor
July 18, 2017

Hi Anna,

I think he was doing a code sample, not asking.

Carles.

TanmeyTWX17-PeridotAuthor
17-Peridot
July 18, 2017

Hi Ann/Carles,

My approach didn't work for me. It neither throw any error nor any data display onto grid. I'm getting Grid with blank rows as below.

1-Visitor
July 18, 2017

You must use AddField snippet on the result previous adding data.

TanmeyTWX17-PeridotAuthor
17-Peridot
July 18, 2017

Carles,

Sorry, didn't get you.