12 Replies Latest reply on Nov 8, 2011 6:01 AM by bucpatr1

    Editing datagrid using DropDown List

    Zolotoj Level 3

      I need to provide a list of choices for a user to select from in datagrid's column.

      I am using classFactory to specify a class for the item Editor of that column. I am using startItemEditorSession to start editing session

      and I am using  endItemEditorSession to end it. After I run endItemEditorSession the data in the column is shown as [object ListItem].

      Do I need to have an item Renderer as well for this column? Because my understanding I dont need it.

       

      Thanks

        • 1. Re: Editing datagrid using DropDown List
          kevinklin Adobe Employee

          Yes, you'll need an item renderer to display the right field from your data for that column.

          • 2. Re: Editing datagrid using DropDown List
            Zolotoj Level 3

            Ok, then how will I get data from an item Editor into an item Renderer to show the data just being selected from the dropdown?

            • 3. Re: Editing datagrid using DropDown List
              Zolotoj Level 3

              Is it necessary for columns with Combos only or for any type of control? Because for my text fields it works fine with item Editors only being provided.

              • 4. Re: Editing datagrid using DropDown List
                kevinklin Adobe Employee

                Actually, if I'm understanding you correctly, you just need to set the dataField correctly on the GridColumn. It looks like the item renderer just isn't getting the right field from the data to display

                • 5. Re: Editing datagrid using DropDown List
                  Zolotoj Level 3

                  <need to set the dataField correctly on the GridColumn

                  Not sure what does "correctly" here mean because I have dataField="df1" and it does match the dataProvider's column.

                  • 6. Re: Editing datagrid using DropDown List
                    kevinklin Adobe Employee

                    what is your data object? Does data.df1.toString() return the right thing? I'd try this outside of the DataGrid to make sure.

                    • 7. Re: Editing datagrid using DropDown List
                      Zolotoj Level 3

                      My data object is ArrayCollection. I am changing my code to this:

                      <s:itemRenderer>

                                              <fx:Component>

                                                  <s:GridItemRenderer>

                                                      <s:Label text="{data.FamhistRelationshipCode}"/>

                                                  </s:GridItemRenderer>   

                                              </fx:Component>

                                          </s:itemRenderer>

                       

                      I used XML to get rid of a binding message.

                      How can I check what data.FamhistRelationshipCode actually is?

                      • 8. Re: Editing datagrid using DropDown List
                        kevinklin Adobe Employee

                        Try putting a breakpoint on this line: <s:Label text="{data.FamhistRelationshipCode}"/>. When it breaks, examine what data.FamhistRelationshipCode using the debugger.

                        • 9. Re: Editing datagrid using DropDown List
                          Zolotoj Level 3

                          Yes, I have breakpoint at this line. I am getting there when datagrid is loading but data has not been set, so I have null for data. Then I am getting when an empty row is added, but I am not getting there when something is selected in the dropdown.

                          • 10. Re: Editing datagrid using DropDown List
                            kevinklin Adobe Employee

                            Can you create a simple test example?

                            • 11. Re: Editing datagrid using DropDown List
                              Zolotoj Level 3

                              Not sure I can simplify that much.

                              But here is what I have:

                              Column:

                              <editabledatagrid:EditableDataGridColumn

                                                  dataField="FamhistRelationshipCode"

                                                  editable="true"

                                                  headerText="Relationship">

                                              </editabledatagrid:EditableDataGridColumn>

                               

                              Grid creationComplete="grid_creationCompleteHandler(event)"

                              protected function grid_creationCompleteHandler(event:FlexEvent):void

                                          {

                                              // TODO Auto-generated method stub

                                              var renderer1:ClassFactory = new ClassFactory(LabelItemRenderer);

                                              var editor1:ClassFactory = new ClassFactory(DropDownItemRenderer);

                                              var col1:EditableDataGridColumn = EditableDataGridColumn(grid.columns.getItemAt(0));

                                              col1.itemEditor = editor1;

                                              col1.itemRenderer = renderer1;

                                          }

                              That takes me a bit further.

                              But when I start editing session I am getting:

                              Error: Object reference not set to an instance of an object.

                              If I dont create item Renderer I am not getting the error. Any idea?

                               

                              Thanks for the help.

                              • 12. Re: Editing datagrid using DropDown List
                                bucpatr1 Level 2

                                The first thing I see is that you don't need to create a sub-class of Column, the standard Column class should provide everything you need to specify an itemrenderer for the column. The other thing I would look at is your DropDownItemRenderer class. From the error you described it sounds like you didn't specify a labelFunction or labelField that tells the dropdown how to display the data.