Struct Table configs

Is it possible to dynamically change struct table configs?

I would like to change “w.columns” with javascript in this example:

firstName, lastName, displayName, jersey, height, hometown, class, major, active

Hi David,

There is no easy native method to affect the configs on a param view however you can easily accomplish this with a setXML method. I’ve included an example of this below. If that does not suffice the next direction I would take you would be a script table but I feel that would be more trouble than its worth in this case.

firstName, lastName, displayName, jersey, height, hometown, class, major, active var cols = ["firstName", "lastName", "displayName", "jersey"," height", "hometown", "class", "major", "active"]; var colsString = cols.join(", "); var oglml = '\n\ ' + colsString + '\n\ ';

ogscript.setXML(‘roster5-container’, oglml);


var cols = [“firstName”, “lastName”, “jersey”," height", “active”];
var colsString = cols.join(", ");
var oglml = ‘\n
’ + colsString + '\n\

';

ogscript.setXML(‘roster5-container’, oglml);

Thanks this is great!

Is there a way to sort the data on one of the columns with javascript?

I’d rather not re-write data in the param.

I just want to change how the data is displayed.

If I can do it without making the user click that would be great,

Hey David,

There’s a simpler way to do this without javascript if your okay with just clicking the column header you want to use to sort. The trick is the w.sortable config option. This option allows you to click on the header for each column and it will first sort the table rows based on that columns data and the the second time clicked it will reverse sort the table. However any method for sorting will impact the actual saved data order so I think I good way to counteract this would be to add a Row Id column that enumerates based on the true order of the Struct Array. That way if you click on the Row Id column you can use that to get your rows back to the correct order easily.

Below is an example of that.

rowid, firstName, lastName, displayName, jersey, height, hometown, class, major, active true var cols = ["rowid", "firstName", "lastName", "displayName", "jersey"," height", "hometown", "class", "major", "active"]; var colsString = cols.join(", "); var oglml = '\n\ ' + colsString + '\n\ true\n\ ';

ogscript.setXML(‘roster5-container’, oglml);


var cols = [“rowid”, “firstName”, “lastName”, “jersey”," height", “active”];
var colsString = cols.join(", ");
var oglml = ‘\n
’ + colsString + '\n
true\n\

';

ogscript.setXML(‘roster5-container’, oglml);

If this is not your desired workflow there are other methods that yes use JavaScript however you would still run into the issue of the order of the rows displayed will impact the order of the rows in your struct.

Please let me know if you want further assistance with the JavaScript method instead.

Just a slight clarification/correction: clicking on the column headers only changes the way the data is displayed. It does not impact the actual ordering of the data underneath.

Also, another way to make the columns dynamic would be to switch from struct tables to array tables (where each array parameter provides a single column and the entire table is controlled by a choice constraint enumerating the OIDs of the column parameters). With this type of table, if you update the choice constraint on the parameter that defines the table, it will impact which columns are displayed. The downside to this is that your records would need to shift away from using struct arrays to define each row (which is very nice to look at especially if you’re exporting the data to Datalinq). Still, just for completeness, I’ll show the example:

Advanced Basic col1 col2 col3 a b c d e f g 1 2 3 4 5 6 7 i ii iii iv v vi vii var cArray = null; if (this.getValue() == 0) { cArray = ['col1', 'col2', 'col3']; } else { cArray = ['col1', 'col2']; }

var choiceConstraint = params.createStringChoiceConstraint(cArray);
params.replaceConstraint(‘params.table’, choiceConstraint);