Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid OptionDataSources and Sort

    Hi,

    We have a list grid showing data of table X with 3 columns having the OptionDataSource enabled to the same table X (displaying the NAME field instead of the ID). Everything is all right in the grid itself.

    If we configure the sort and add a column which has an option datasource, it does not work and the sorted column becomes the NAME field in the grid, instead of the desired field (whose display field is X.NAME).

    Who can we fix this?
    (We are using SGWT Power 4.1)

    Thanks,
    Thomas

    #2
    Sorry, that's not nearly enough information to enable anyone to help you. Try taking a look at the FAQ to remind yourself of the information you need to post.

    Comment


      #3
      All right, here is a small test case:

      A sample datasource:

      Code:
      <DataSource ID="test" serverType="sql" tableName="SEC_OPERATOR">
      	<fields>
          	<field name="ID" type="sequence" primaryKey="true" />
              <field name="CREATED" type="creatorTimestamp" />
              <field name="CREATED_BY" type="integer" />
          	<field name="UPDATED" type="modifierTimestamp" />
              <field name="UPDATED_BY" type="integer" />
              <field name="NAME" type="text" />
          </fields>
      </DataSource>
      Some code:

      Code:
      DataSource.load("test", new Function() {
      			@Override
      			public void execute() {
      				ListGrid test = new ListGrid(DataSource.get("test"));
      				test.setWidth(600);
      				test.setHeight(300);
      				test.setAutoFetchData(true);
      				test.setFields(
      						new ListGridField("ID"), 
      						new ListGridField("CREATED"), 
      						new ListGridField("CREATED_BY"), 
      						new ListGridField("UPDATED"), 
      						new ListGridField("UPDATED_BY"), 
      						new ListGridField("NAME"));
      				test.getField("CREATED_BY").setOptionDataSource(DataSource.get("test"));
      				test.getField("CREATED_BY").setValueField("ID");
      				test.getField("CREATED_BY").setDisplayField("NAME");
      				test.getField("UPDATED_BY").setOptionDataSource(DataSource.get("test"));
      				test.getField("UPDATED_BY").setValueField("ID");
      				test.getField("UPDATED_BY").setDisplayField("NAME");
      				
      				test.show();
      				
      			}
      		}, true);
      If I simply click on the CREATED_BY column to sort it, the NAME column gets sorted instead. Same problem if I go to "Configure Sort" dialog.

      Regards,

      Thomas

      Comment


        #4
        Provide all ListGridField settings before calling setFields().

        Comment


          #5
          What do you mean? I should configure the OptionDataSources (through all the getField() calls) before calling setFields()?
          All the information is provided here, not less. Using this, I can reproduce the problem without any additional line of code.

          Comment


            #6
            Code:
            ListGridField id = new ListGridField("ID");
            ListGridField c = new ListGridField("CREATED");
            ListGridField cb = new ListGridField("CREATED_BY");
            cb.setOptionDataSource(DataSource.get("test"));
            cb.setValueField("ID");
            cb.setDisplayField("NAME");
            ListGridField u = new ListGridField("UPDATED");
            ListGridField ub = new ListGridField("UPDATED_BY");
            ub.setOptionDataSource(DataSource.get("test"));
            ub.setValueField("ID");
            ub.setDisplayField("NAME");
            ListGridField n = new ListGridField("NAME"));
            test.setFields(id, c, cb, u, ub, n);
            test.show();

            Comment


              #7
              To restate, if you plan to call any setters on your ListGridField instances, call them all before setFields().

              Comment


                #8
                Ok thanks! I take note of this best practice.
                But, anyway, as I may have expected, it does not change anything. Here is my update code sample, and the problem remains... If I sort on the CREATED_BY or UPDATED_BY columns, the NAME column is sorted instead.

                Code:
                ListGrid test = new ListGrid(DataSource.get("test"));
                				test.setWidth(600);
                				test.setHeight(300);
                				test.setAutoFetchData(true);
                				ListGridField idField = new ListGridField("ID");
                				ListGridField createdField = new ListGridField("CREATED");
                				ListGridField createdByField = new ListGridField("CREATED_BY");
                				ListGridField updatedField = new ListGridField("UPDATED");
                				ListGridField updatedByField = new ListGridField("UPDATED_BY");
                				ListGridField nameField = new ListGridField("NAME");
                
                				createdByField.setOptionDataSource(DataSource.get("test"));
                				createdByField.setValueField("ID");
                				createdByField.setDisplayField("NAME");
                				updatedByField.setOptionDataSource(DataSource.get("test"));
                				updatedByField.setValueField("ID");
                				updatedByField.setDisplayField("NAME");
                				test.setFields(idField, createdField, createdByField, updatedField, updatedByField, nameField);
                				
                				test.show();
                Thanks,
                Thomas

                Comment


                  #9
                  What do you mean by "the NAME column is sorted instead"? Certainly, the ListGrid does not switch over to sorting by the field named "NAME", highlight that header, etc. So you must mean that you don't like something in the request you see to the server?

                  Before answering, first read the docs for ListGridField.optionDataSource, and in particular, the suggestion to use includeFrom for this use case instead.

                  Comment


                    #10
                    Originally posted by Isomorphic View Post
                    So you must mean that you don't like something in the request you see to the server?
                    .. or perhaps you mean that the apparent sort order follows the alphabetical order of the NAME column. But in fact, sorting is being done on the ID values from the createdByField/updatedByField and perhaps this just happens to put the NAME column values in alphabetical order (we can't tell because you didn't share data).

                    Again, includeFrom is the correct solution here - see the docs.

                    Comment


                      #11
                      Thank you.

                      Yes, if I click the CREATED BY column, the NAME column is sorted, highlighted etc.. exactly like if I clicked on the NAME column. I can "understand" that, as the OptionDataSource points to the same table and the display field is NAME.

                      I've of course read the documentation, and I'm asking for help here. The Datasource does not seem to like having multiple joins to the same table (with foreignKey and includeFrom) in its definition. If there's a way to do this, well, I did not find it clearly described in the docs. Please also note that (in our real example) the data source is completely cached on the client side.

                      Thanks,
                      Thomas

                      Comment


                        #12
                        You mention client-side caching, what specific mechanism is this? clientOnly DataSource? cacheAllData:true?

                        Note: it's critical to provide this kind of basic information up front. You've shown us a SQL DataSource when that's apparently not what you're actually using, and because of this all previous commentary was basically a waste of time.

                        Comment


                          #13
                          Oh, it was just to underline that having the OptionDataSource set on the client side, in our real implementation, has no impact in terms of performance. Nothing else.
                          For this particular issue, you have 100% of the code required to reproduce the problem, and I did not enable any caching feature on my side.

                          Comment


                            #14
                            The problem with showing a SQL DataSource is that we were giving advice for a better approach for SQLDataSource that would avoid this issue entirely, as well as scale and perform better.

                            We'll still check on this possible bug, but to get good advice, tell us in advance if a test case you're providing doesn't match your real use case.

                            Comment


                              #15
                              If you switch on INFO level logging and open up the Developer Console, you should see logs that indicate what the problem is here.

                              To avoid the behavior you're seeing, setSortByDisplayField(false) on the fields with optionDataSources.

                              Comment

                              Working...
                              X