Announcement

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

    Datasource:field:optionDataSource, sortField: Editing vs Filtering

    BEHAVIOR of sortField with editing vs filtering:

    The pull down when editing sorts the continents.

    Versus when filtering continents, the pull down for filtering does not list the continents in a sorted order?

    ENVIRONMENT:
    1.smartgwtpower-3.0p downloaded on 09-18-2012

    2. MacOSX 10.8.1,
    Eclipse Indigo Service Release 2 Build id: 20120216-1857
    chrome and eclipse:runOnServer
    Tomcat 7.0.27

    3,4, and 5 not apropos


    MODIFICATIONS TO EXAMPLE in EE Showcase:

    Variation of SmartGWT EE Showcase->Java Data Integration -> SQL ->Basic Connector.

    1. I imported the world.data.xml into MySQL.
    2. I normalized the table by adding a Continent table.
    3. I added attribute sortField to the continent field.

    Code:
    <DataSource  
        ID="worldDS"  
        serverType="sql"  
        tableName="worldDS"  
    >  
        <fields>  
            <field name="pk"            type="sequence"   hidden="true"            primaryKey="true" />  
            <field name="countryCode"   type="text"       title="Code"             required="true"   />  
            <field name="countryName"   type="text"       title="Country"          required="true"   />  
            <field name="capital"       type="text"       title="Capital"          />  
            <field name="government"    type="text"       title="Government"       length="500"      />  
            <field name="continent"     type="integer"       title="Continent"
                 optionDataSource="Continent"
                 valueField="pk"
                 displayField="name"
                 sortField="name"
                 />
            <field name="independence"  type="date"       title="Nationhood"          />  
            <field name="area"          type="float"      title="Area (km2)"		  />  
            <field name="population"    type="integer"    title="Population"          />  
            <field name="gdp"           type="float"      title="GDP ($M)"            />  
            <field name="member_g8"     type="boolean"    title="G8"                  />  
        </fields>  
    </DataSource>
    and

    Code:
    <DataSource  
        ID="Continent"  
        serverType="sql"  
        tableName="Continent"  
    >  
        <fields>  
            <field name="pk"            type="sequence"   hidden="true"            primaryKey="true" />  
            <field name="name"   type="text"       title="Continent"             required="true" />  
        </fields>  
    </DataSource>
    Last edited by michaeljseo; 18 Sep 2012, 11:37.

    #2
    Here's a Solution

    I added a fetch operationId="byName" to my Continent.ds.xml and set the attribute optionOperationId in my worldDS.ds.xml. Now both my filter and editor pull down sorts the continents.

    Code:
    <DataSource  
        ID="Continent"  
        serverType="sql"  
        tableName="Continent"  
    >  
        <fields>  
            <field name="pk"            type="sequence"   hidden="true"            primaryKey="true" />  
            <field name="name"   type="text"       title="Continent"             required="true" />  
        </fields>  
    
    <operationBindings>
       <operationBinding operationId="byName" operationType="fetch">
          <orderClause>
             name asc
          </orderClause>
       </operationBinding>
       <operationBinding operationId="byID" operationType="fetch">
          <orderClause>
             pk asc
          </orderClause>
       </operationBinding>
    </operationBindings>
    
    </DataSource>

    and added the attribute optionOperationId="byName"

    Code:
    <DataSource  
        ID="worldDS"  
        serverType="sql"  
        tableName="worldDS"  
    >  
        <fields>  
            <field name="pk"            type="sequence"   hidden="true"            primaryKey="true" />  
            <field name="countryCode"   type="text"       title="Code"             required="true"   />  
            <field name="countryName"   type="text"       title="Country"          required="true"   />  
            <field name="capital"       type="text"       title="Capital"          />  
            <field name="government"    type="text"       title="Government"       length="500"      />  
            <field name="continent"     type="integer"       title="Continent"
    			 filterEditorType="selectItem"
                 optionDataSource="Continent"
                 optionOperationId="byName"
                 valueField="pk"
                 displayField="name"
                 sortField="name"
                 />
            <field name="independence"  type="date"       title="Nationhood"          />  
            <field name="area"          type="float"      title="Area (km2)"		  />  
            <field name="population"    type="integer"    title="Population"          />  
            <field name="gdp"           type="float"      title="GDP ($M)"            />  
            <field name="member_g8"     type="boolean"    title="G8"                  />  
        </fields>  
    </DataSource>

    Comment


      #3
      I have the same problem but I have the pro edition, which doesn't allow custom sql. Is there some solution to have the filter combobox's display value be sorted?

      Comment


        #4
        You just set sortField on the ComboBoxItem.

        The previous poster's solution is massive overkill and should not be used.

        Comment


          #5
          Hi,

          I set sortField on the combobox in the form and that works just fine. But we're talking about the combobox in the filter above the grid here. I haven't put it there explicitly (it's great that smartgwt figures it all out by itself), the only problem is that the entries aren't sorted.
          Is there some way to access that combobox?

          Comment


            #6
            See listGridField.filterEditorProperties.

            Comment


              #7
              Do you mean using filterEditorProperties.getOptionCriteria()?
              Should I set an attribute in order to indicate the sort order?
              How would that be used?

              Comment


                #8
                Set comboBoxItem.sortField via listGrid.setFilterEditorProperties.

                Comment


                  #9
                  I'm having an error when I try that. Here's my code:
                  Code:
                  		FormItem filterEditorProperties=new FormItem();
                  		
                  		filterEditorProperties.getOptionCriteria().setAttribute("comboBoxItem.sortField", "nombre");
                  		field.setFilterEditorProperties(filterEditorProperties);
                  Now instead of just a few columns, all my columns are shown, and when I click I get an error messae, so I guess this is not exactly what you meant. Can you clarify a bit more?

                  Comment


                    #10
                    You're overcomplicating this. Your filterEditorProperties should be an instance of ComboBoxItem and you should call setSortField() on that directly (no setAttribute).

                    Also, forget about optionCriteria, that was never the correct approach (which is why we didn't bring it up).

                    Comment


                      #11
                      Here's an explicit example from my own notes. Maybe useful to someone else.

                      The data source of my grid:

                      Code:
                      <DataSource
                      ...
                      ID="AccountTransaction"
                      >
                      <fields>
                      <field name="id" type="sequence" primaryKey="true"/>
                        <field name="incoming_transaction_number" title="Assoc. Transaction No." type="integer"/>
                      ...
                        <field name="transaction_type_id" title="Transaction Type" type="integer"
                          optionDataSource="TransactionType"
                          valueField="id"
                          displayField="transaction_type"/>
                      ...
                      </fields>
                      ...
                      </DataSource>
                      ...That uses the following data source as an optionDataSource:

                      Code:
                      <DataSource
                      ...
                      ID="TransactionType"
                      ...
                      >
                      <fields>
                        <field primaryKey="true" name="id" type="sequence" hidden="true"/>
                        <field name="transaction_type" title="Transaction Type" length="25" type="text"/>
                      </fields>
                      </DataSource>
                      To apply proper sorting (say we want to sort on the "transaction_type" field of TransactionType instead of the default "id" field),
                      we FilterEditorProperties on the field when construting the grid:

                      Code:
                      transactionGrid = new ListGrid();
                      ...
                      ListGridField typeField = new ListGridField(AccountTransactionIF.TRANSACTION_TYPE_ID);
                      ComboBoxItem properties = new ComboBoxItem();
                      properties.setSortField(TransactionTypeIF.TRANSACTION_TYPE);
                      typeField.setFilterEditorProperties(properties);
                      ...
                      transactionGrid.setFields(
                      ...
                        typeField,
                      ...
                        commentField);

                      Comment

                      Working...
                      X