6 Replies Latest reply on Oct 19, 2010 9:52 AM by clem_c_rok

    Can't select certain rows in datagrid

    clem_c_rok Level 1

      Hello,

       

          I have a datagrid with 3 columns, that works great until you have 2 rows next to each other w/ the exact first name and last name.

       

      When that happens, I can select the top row but I can't select the bottom row.

       

      If I trace the onPatientSelected method, it never gets called.

       

      here's my datagrid code below:

       


      <code>
                  <mx:DataGrid
                      id="patientList"
                      dataProvider="{dataProvider}"
                      change="onPatientSelected()"
                      styleName="patientlist"
                      width="100%"
                      height="100%"
                      editable="false"
                      draggableColumns="false"
                      resizableColumns="false" headerRelease="checkColumnSorted(event)">
                     
                      <mx:columns>
                          <mx:DataGridColumn headerText="Last Name"  dataField="LastName" />
                          <mx:DataGridColumn headerText="First Name" dataField="FirstName"/>
                          <mx:DataGridColumn headerText="Unique Id" dataField="UniqueId" sortable="false"/>
                      </mx:columns>
                 
                  </mx:DataGrid>
      </cod>

       

      Any ideas?
        • 1. Re: Can't select certain rows in datagrid
          Flex harUI Adobe Employee

          Each item in the dataprovider must be unique.  If you have references to the

          same object at two different indexes things will not work as expected.

          • 2. Re: Can't select certain rows in datagrid
            clem_c_rok Level 1

            The thing is that they ARE 2 different objects.        Each selectedIndex represents different objects.

             

            For instance, the top row  = patientList.selectedItem.PatientId: 191

             

            and the duplicate row below = patientList.selectedItem.PatientId: 192

            • 3. Re: Can't select certain rows in datagrid
              Flex harUI Adobe Employee

              Can you make a small test case?

              • 4. Re: Can't select certain rows in datagrid
                clem_c_rok Level 1

                The strange thing is that we have datadrids all over this app that are formatted exactly the same way and this behavior never happens:

                 

                Here's another example:

                 

                <code>

                <mx:DataGrid
                                id="contactDataGrid"
                                change="onItemSelected()"
                                styleName="patientlist"
                                width="50%"
                                height="100%"
                                editable="false"
                                draggableColumns="false"
                                resizableColumns="false" >
                               
                                <mx:columns>
                                    <mx:DataGridColumn headerText="Name" dataField="FirstName" />
                                    <mx:DataGridColumn headerText="Relationship" dataField="RelationshipToPatientTypeId"/>
                                </mx:columns>
                   
                            </mx:DataGrid>

                </code>

                • 5. Re: Can't select certain rows in datagrid
                  Flex harUI Adobe Employee

                  I don't see anything obvious from the snippets.  I would need a full test

                  case in about 20 lines that I can just copy and paste.

                   

                  I would be careful of your change handler.  Maybe onItemSelected somehow

                  resets selectedItem or selectedIndex.

                  • 6. Re: Can't select certain rows in datagrid
                    clem_c_rok Level 1

                    So the problem has been solved and sorry for the long reply the culprit was the sort function:

                     

                    Previously it was this:           

                     

                    dataProvider.sort.fields = [new SortField("LastName",true, false), new SortField("FirstName",true, false)];

                     

                    and all I had to do was to make it more distinct by adding the PatientId field to the mix.

                     

                    dataProvider.sort.fields = [new SortField("LastName",true, false), new SortField("FirstName",true, false), new SortField("PatientId",true, false)];

                     

                     

                     

                    Thanks for everyone's reply!