Skip to main content
16-Pearl
July 29, 2024
Solved

Force a column to appear first in a grid dynamically

  • July 29, 2024
  • 1 reply
  • 2120 views

Hi,

 

I have a service output of base type infotable. The datashape attached only has 1 column called timestamp. I add all my other columns dynamically in my service. In the result, the timestamp column appears last. Instead I want this column to be the first in the grid. How do I force this column to appear first?

 

Many Thanks.

Best answer by Rocko

I can't reproduce this behaviour. Here, the timestamp column is first.

-Do you have a datashape assigned to your output Infotable variable? if not, try assigning TimestampOnly_DS to it. In Mashup, remove binding, save, reload service, rebind

-in your service, I suppose you add the fields to the infotable using AddField? you can pass an ordinal parameter to that which gives the order of the columns:

result.AddField({name:"f2", baseType:"STRING",ordinal:2});

result.AddField({name:"f3", baseType:"STRING",ordinal:1});

Use that, again, remove binding, save, reload service, rebind.

 

Note that the order of the columns is partially determined at bind time. When you bind to a grid the component tried to find out the columns not only by looking at the columns returned in the service declaration, it (tries to) run the service and checks the result.

Hence, whenever you change the "result style" of your service, try to remove the binding, save, reload service, rebind.

 

 

 

 

1 reply

17-Peridot
July 29, 2024

try to generate grid configuration json dynamically with columns order. Generate the targets values according to your requirement.

"columnDefs": [
 {
 "targets": 0,
 .
 .
 },
 {
 "targets": 1,
 .
 .
 }
 ]

 Refer few articles below,

Janicen16-PearlAuthor
16-Pearl
July 29, 2024

where do I pass the 

columnDefs

in the creation of my table?

let outputTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "TimestampOnly_DS"
});

 

Regards

17-Peridot
July 29, 2024

You can create separate service (GetGridConfiguration()) and the output should be JSON. The complete json format you can reuse from above mentioned community post.

 

There is widget property called "Grid Configuration". You have pass as JSON from the service.