Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex, ColdFusion

Adobe Flex: Article

Adobe Flex 2: Advanced DataGrid

Part 1: Destination-awareness formatters & renderers

Flex creators thought of this in advance. An object referenced by itemRenderer is not a CheckBox but rather an instance of mx.core.ClassFactory wrapped around the CheckBox. The mechanism of mx.core.ClassFactory allows Flex to generate instances of another class - in our case com.theriabook.controls.CheckBox. Importantly, each instance created by the factory is assigned identical properties borrowed from the properties property of the factory object. Accordingly, all we have to do is pass the value of the extendedProperties as the properties of the itemRenderer as shown in Listings 12.

The test application, ExtendedPropertiesDemo, is in Listing 13. When you run it, it produces the data grid shown in Figure 6.

We should have mentioned the alternative run-of-the-mill approach with inline itemRenderer. It's in Listing 14.

Arguably, the extendedProperties approach is more efficient, since it absolves MXML of generating an extra nested class (mx:Component) for each column of this kind and we've introduced you to yet another mean of customizing a DataGridColumn. We'll continue building on top of it in the following sections.

Nitpicking CheckBox
There are some additional remarks that we ought to add to our CheckBox implementation at this point. The first one is related to the horizontal alignment of the CheckBox. Instincts tell us that label-free checkbox should be centered in the column, rather than stuck in the leftmost position. At first, you may try the textAlign style of the DataGridColumn to no avail. Then you may resort to another run-of-the-mill approach to center the Checkbox by putting it inside a container, such as HBox. Here's the performance-based advice endorsed by Flex Framework engineers: avoid containers inside the datagrid cell at any reasonable cost. In particular, instead of using HBox, why not sub-class the CheckBox and override the updateDisplayList method? It gets quite natural once you've stepped on this path, so we'll add the code shown below to our CheckBox (the complete code of com.theriabook.controls.CheckBox is in Listing 15):

   import mx.core.mx_internal;
   use namespace mx_internal;
    . . . .
     override protected function updateDisplayList(
      unscaledWidth:Number, unscaledHeight:Number):void
      super.updateDisplayList(unscaledWidth, unscaledHeight);
      if (currentIcon) {
       var style:String = getStyle("textAlign");
       if ((!label) && (style=="center") ) {
        currentIcon.x = (unscaledWidth - currentIcon.measuredWidth)/2;

Please note the use of namespace mx_internal. It's required so the reference to currentIcon visualizes the checkbox picture, since the currentIcon, the child of the original CheckBox, is originally scoped as mx_internal.

Now we modify the testing application to include textAlign="center":

    <fx:DataGridColumn dataField="BENE_DAY_CARE" textAlign="center"
      itemRenderer="com.theriabook.controls.CheckBox" >
        <mx:Object onValue="Y" offValue="N" />

And, when we run it, all checkboxes are in their proper places:

The second nitpicking point is related to undefined as the possible value of a property. Under our current business scenario, we can assume that some of the employees are not eligible for day care benefits, and relevant items in the dataProvider's collection are lacking BENE_DAY_CARE property, which can be expressed as item.BENE_DAY_CARE=="undefined" for dynamic items. (See Figure 7)

Does it make sense to show checkboxes for non-eligible employees? Perhaps, it doesn't. In these cases we would make currentIcon invisible. You may select a different approach and show a fuzzy checkbox image instead, but that is beside the point. The following modification of updateDisplayList does the job of removing checkBox when the value is undefined:

override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void

      super.updateDisplayList(unscaledWidth, unscaledHeight);
      if (currentIcon) {
        var style:String = getStyle("textAlign");
        if ((!label) && (style=="center") ) {
          currentIcon.x = (unscaledWidth - currentIcon.measuredWidth)/2;
        currentIcon.visible = (_value!=undefined);

To accommodate this change we also have to loosen up the class definitions for value as shown in Listing 15, where we change Object to undefined.

Next and probably the most important fix is that our CheckBoxes have been silenced. Try to click on one, scroll the row out of view, and scroll it back in. The checkbox doesn't retain your selection and it shouldn't: we have never communicated the change to the underlying data. To remedy this situation we'll add the constructor method, where we'd start listening on the "change" event; once an event is intercepted we'll modify the data item with the CheckBox value. That, in turn, will result in either onValue or offValue as per our value getter:

    public function CheckBox() {
          if (listData) {
            data[DataGridListData(listData).dataField] = value;

The complete code for the second version of CheckBox is in Listing 15.

Next comes the test application in Listing 16. We've added the "Revoke day care benefit" button, which makes DAY_CARE_BENE undefined on the currently selected DataGrid item. We also had to notify the collection with the itemUpdated() call.

When you run the application, you'll see that checkboxes retain the selection after scrolling out and back into view. If you click the "Revoke" button for the first two rows, you're going to see a picture similar to Figure 8.

The last CheckBox fix will come in handy once you declare the DataGrid editable. Why declare it editable in the first place if we seem to be editing the DataGrid already? Let's not forget that the only field we've edited so far is the checkbox BENE_DAY_CARE. Should you also decide to allow editing the text fields you'd have to change the definition of the DataGrid as shown in bold in this snippet:

    <fx:DataGrid id="dg" creationComplete="dg.fill();dg.selectedIndex=0;" editable="true"
     destination="com_theriabook_composition_EmployeeDAO" method="getEmployees" >

But once you do that, a click on our beautiful checkbox would turn it into default editor - TextInput, quite like in a Cinderella story. To make the miracle last, you'd declare that your renderer is good to go as an editor as well:

    <fx:DataGridColumn dataField="BENE_DAY_CARE" textAlign="center"
      itemRenderer="com.theriabook.controls.CheckBox" rendererIsEditor="true">
      . . .

By default, DataGrid reads the text property of the item editor. You can nominate a different property via editorDataField (in our case that would be value). Alternatively, and what will help us later, you can "upgrade" the checkbox to carry the text property itself:

    public function set text(val:String) :void {
      value = val;

    public function get text():* {
      return value;

While DataGrid is a powerful component right off-the-shelf, but the fact that it's truly extendable can substantially increase its usability. In the next part of this article, we'll continue experimenting with the DataGrid by using radio buttons as renderers and introduce computed columns.

More Stories By Victor Rasputnis

Dr. Victor Rasputnis is a Managing Principal of Farata Systems. He's responsible for providing architectural design, implementation management and mentoring to companies migrating to XML Internet technologies. He holds a PhD in computer science from the Moscow Institute of Robotics. You can reach him at [email protected]

More Stories By Yakov Fain

Yakov Fain is a Java Champion and a co-founder of the IT consultancy Farata Systems and the product company SuranceBay. He wrote a thousand blogs (http://yakovfain.com) and several books about software development. Yakov authored and co-authored such books as "Angular 2 Development with TypeScript", "Java 24-Hour Trainer", and "Enterprise Web Development". His Twitter tag is @yfain

More Stories By Anatole Tartakovsky

Anatole Tartakovsky is a Managing Principal of Farata Systems. He's responsible for creation of frameworks and reusable components. Anatole authored number of books and articles on AJAX, XML, Internet and client-server technologies. He holds an MS in mathematics. You can reach him at [email protected]

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

IoT & Smart Cities Stories
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists examined how DevOps helps to meet the de...
According to Forrester Research, every business will become either a digital predator or digital prey by 2020. To avoid demise, organizations must rapidly create new sources of value in their end-to-end customer experiences. True digital predators also must break down information and process silos and extend digital transformation initiatives to empower employees with the digital resources needed to win, serve, and retain customers.
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, will provide an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life ...
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
Rodrigo Coutinho is part of OutSystems' founders' team and currently the Head of Product Design. He provides a cross-functional role where he supports Product Management in defining the positioning and direction of the Agile Platform, while at the same time promoting model-based development and new techniques to deliver applications in the cloud.
@CloudEXPO and @ExpoDX, two of the most influential technology events in the world, have hosted hundreds of sponsors and exhibitors since our launch 10 years ago. @CloudEXPO and @ExpoDX New York and Silicon Valley provide a full year of face-to-face marketing opportunities for your company. Each sponsorship and exhibit package comes with pre and post-show marketing programs. By sponsoring and exhibiting in New York and Silicon Valley, you reach a full complement of decision makers and buyers in ...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...
LogRocket helps product teams develop better experiences for users by recording videos of user sessions with logs and network data. It identifies UX problems and reveals the root cause of every bug. LogRocket presents impactful errors on a website, and how to reproduce it. With LogRocket, users can replay problems.
Data Theorem is a leading provider of modern application security. Its core mission is to analyze and secure any modern application anytime, anywhere. The Data Theorem Analyzer Engine continuously scans APIs and mobile applications in search of security flaws and data privacy gaps. Data Theorem products help organizations build safer applications that maximize data security and brand protection. The company has detected more than 300 million application eavesdropping incidents and currently secu...