Tech Articles


Dynamic Runtime DataWindow Group Creation


Here’s a DataWindow tip…and a half.

Unless you want to dynamically build a DataWindow object from scratch at runtime (it’s do-able…but quite involved), there’s no direct way to create a group for a DataWindow object in an ad hoc manner. Here’s a workaround.

First, insert a computed field in an extant DataWindow object and give it an expression that’s an empty string. For the sake of this tip the computed field’s name will be “dynamicgroup”.

image

 

 

 

 

 

 

 

 

Then create a group based on this computed field.

Image

 

 

 

 

 

 

 

 

 

 

image

 

 

 

 

 

 

 

Format the DataWindow object according to your needs and save.

Now at runtime, modify the computed field’s expression to have the value of the column name by which you wish to group the result set.

dw_employees.setredraw( FALSE )

dw_employees.Modify(“dynamicgroup.Expression='” + as_coltogroup + “‘” )

dw_employees.setsort( as_coltogroup + ” A”)

dw_employees.sort( )

dw_employees.groupcalc( )

dw_employees.setredraw( TRUE )

After calling SetSort() and Sort() to sort by the column on which you’re grouping, don’t forget to call GroupCalc() to recalculate the breaks in the groupings.

Certainly this technique may be adapted to implement more than one grouping level. For those of you who maintain and enhance frameworks, the sample code fragment can certainly be made more generic as far as the reference to the DataWindow control and to the name of the computed field(s).

OK, here’s the half (.5) tip.

You’ve defaulted the value of the computed field’s expression to an empty string. This will work fine for grouping on columns of type string. However, for columns of other data types, you’ll need to invoke the DataWindow expression function String() to convert the non-string columns’ values to strings in order for the runtime modification to have the desired effect. Here’s how the accommodation appears in the sample code from earlier in this tip…

dw_employees.Modify(“dynamicgroup.Expression=’String(” + as_coltogroup + “)'” )

Comments (0)
There are no comments posted here yet

Find Articles by Tag

Automated Testing Oracle Git OAuth 2.0 SQL Import JSON Menu .NET Assembly PDF Source Code Web Service Proxy Database Table Schema Event Handler Transaction XML Authorization ActiveX Jenkins Repository JSONGenerator PowerBuilder Compiler Data Validation SnapObjects RichTextEdit Control MessageBox RibbonBar CI/CD Variable NativePDF Model Filter Array External Functions TreeView PowerServer Web Event Handling DevOps PostgreSQL DragDrop OAuth RESTClient Export JSON CrypterObject Branch & Merge GhostScript Syntax Database Object Authentication CoderObject Configuration TFS REST Sort Database Web API Migration Stored Procedure Encryption Export JSON Deployment Windows 10 Icons SnapDevelop Database Connection Debugger Encoding PostgreSQL ODBC driver .NET Std Framework Application Azure DataWindow Linux OS Android PFC Script SqlExecutor SVN SQL Server Installation Messagging 32-bit Excel TLS/SSL PBDOM Database Profile UI PowerScript (PS) Database Table Data Performance Window OrcaScript OLE Visual Studio Platform InfoMaker Outlook C# DataWindow JSON Mobile Database Table Trial Interface Graph DLL iOS Testing Expression Elevate Conference BLOB Windows OS Debug Event PBNI .NET DataStore SDK HTTPClient PBVM Open Source DataType PowerBuilder JSONParser Resize PowerBuilder (Appeon) WinAPI Class 64-bit API Error COM Database Painter WebBrowser UI Modernization UI Themes Debugging IDE Icon RibbonBar Builder File SqlModelMapper PowerServer Mobile Import License SOAP TortoiseGit Service Text Bug Design Source Control PDFlib Charts ODBC