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

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