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
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Every organization is facing their own Digital Transformation as they attempt to stay ahead of the competition, or worse, just keep up. Each new opportunity, whether embracing machine learning, IoT, or a cloud migration, seems to bring new development, deployment, and management models. The results are more diverse and federated computing models than any time in our history.
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
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 settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...