8 Replies Latest reply on Sep 13, 2011 1:24 PM by Flex harUI

    CheckBox renderers for DataGrids

    Kristin95762 Level 1

      I've been studying this post:

       

      http://www.benclinkinbeard.com/2007/11/efficient-reusable-and-centered-checkbox-renderers- for-datagrids/

       

      However, I'm using FB 4. I don't have experience with any other version prior to flex 4.0. Since this article seems to be dated back to 2007, I'm wondering if there are any changes to the methodology.

       

      Working with an AIR/sqLite app. Want to delete selected entries from a table.

       

      Thanks

       

      Kristin

        • 1. Re: CheckBox renderers for DataGrids
          Amy Blankenship Level 4

          I think the whole reason that this post was even necesary was because the original Check box wasn't written properly (see my comments on this page http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_4.html ).  Note that mx checkbox implements IDataRenderer, so you should be able to use it as a renderer with this tweak, as long as the Spark DataGrid allows you to set column alignment as MX data grid (or you don't need it centered).

           

          In Flex 4, ItemRenderer is really just a Group with a couple of extra bells and whistles.  At the simplest level, you can just bind its selected property to some boolean field on the data object if you know its format in advance.  However, that's not going to give you a reusable check box.  To do that, you need to either write code that can translate the string label field into a Boolean, or something that can combine the DefaultDataGridRenderer's data property with the dataField property on DefaultDataGridRenderer's column object and again come up with a Boolean.

           

          You can either make this Boolean a Bindable variable or, if you're comfortable with the component life cycle, you can do the getter/setter + commitProperties to set it more directly on a custom Check Box skinPart.

           

          HTH;

           

          Amy

          • 2. Re: CheckBox renderers for DataGrids
            Flex harUI Adobe Employee

            My checkbox datagrid example for Spark DataGrid is here:

            http://blogs.adobe.com/aharui/2011/03/spark-checkbox-datagrid-with-drag-and-

            drop-support.html

            • 3. Re: CheckBox renderers for DataGrids
              Kristin95762 Level 1

              Thanks Amy, for your response.

               

              You kinda lost me though.

               

              When it comes to Flex, I'm a kindergartener.

               

              I'm trying to avoid the use of Halo components, and all the terminology is Greek to me. I tend to need good examples, and have them explained, rather than just reading about what I should do.

               

              But thanks. Many of your posts have been quite helpful.

               

              Kristin

              • 4. Re: CheckBox renderers for DataGrids
                Kristin95762 Level 1

                Hello;

                 

                I am new to flex 4. No previous experience with any other version. My experience with Flash was limited to some simple animations, and I made a slot machine app for a final class project a couple of years ago from AS2.

                 

                I have managed to cobble together an application that accesses a sqlite db, entering, retrieving, deleting (a single record) and updating records. I just barely got a handle on using classes.

                 

                So, while your example is magnificent, it's way over my head.

                 

                Might I ask you this? I simply want to load some existing data into a datagrid, select multiple items if desired, and click a button "Delete Selected". What would you suggest for someone who needs a springboard here? Maybe I've just gotten hung up on the idea that the checkbox was the only method.

                 

                Thanks

                 

                Kristin

                • 5. Re: CheckBox renderers for DataGrids
                  Amy Blankenship Level 4

                  Set the datagrids's selectionMode to GridSelectionMode.MULTIPLE_ROWS, then loop through the selectedItems.

                  • 6. Re: CheckBox renderers for DataGrids
                    Flex harUI Adobe Employee

                    For me, there is no better way to learn than picking a starting point,

                    jumping in, and asking questions.  I would think my example has most of what

                    you need.  If you add a button and have its click handler run through the

                    selectedIndices in reverse order, calling removeItemAt, that sounds like

                    what you are asking for.

                     

                    I am more inclined to help folks who ask questions in the form of:  "My code

                    looks like this and I'm getting the following error" as opposed to "I need

                    code that does this, can you write it for me?".  That's because you'll

                    likely learn more by trying, failing and eventually succeeding than taking

                    large chunks of code you don't understand and gluing them together.

                     

                    So, try adding a delete button to the example, and if you get stuck, post

                    the code associated with the delete button and any errors you are getting

                    and someone will probably help you out.

                    • 7. Re: CheckBox renderers for DataGrids
                      Kristin95762 Level 1

                      Hi

                       

                      Nah, not asking for you to write it for me. You've already done that. I just don't understand what I'm looking at. There's a bunch of stuff in there that I can't look up in my Flash Builder 4 Flex 4 Bible. And there's a lot of crap on the net that leads nowhere.

                       

                      I'm a 48 year old mother of three. I'm not inclined to ask someone to do it for me. I just thought I might be stuck in a mode of thinking that was unnecessary.

                      • 8. Re: CheckBox renderers for DataGrids
                        Flex harUI Adobe Employee

                        As a father of a four-year-old, I will offer that the most important shift

                        in my thinking that helped me in software development is the realization

                        that nothing really bad will happen if I try and fail.  I'm not trying to

                        code changes to a pacemaker that is hooked up to someone's heart, or

                        jetliner auto-pilots.  I'm just trying to hack a DataGrid.  99% of the lines

                        of code I write are incorrect and need adjusting, but I learn from those

                        mistakes.  My four-year-old has pretty much the same approach.  He will take

                        train set pieces, remove them, try to add them back in different ways and

                        learns as he goes.  Occasionally, he throws a fit and the train set piece.

                        I would recommend learning about how this example works the same way, by

                        changing pieces and studying the results.  And occasionally throwing fits.

                        I still do.  However, I would recommended that you ask questions on the

                        forums before throwing your computer.