Announcement

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

    Filtering with ComboBox filterEditor type

    Hy Isomorphic,

    SmartClient Version: SC_SNAPSHOT-2012-01-14_v8.2p/LGPL Deployment (built 2012-01-14)

    I ran into a problem when I want to filter a Listgrid witch has this fieldset:
    Code:
    dataProperties: {useClientFiltering:false},
    fields: [
    {name:"id", primaryKey:"true"},
    {name:"code", title:"Code"},
    {name:"department_id", title:"Department", required:true,
                 editorType: "ComboBox",
                 optionDataSource:"departmentsDS",
                 valueField:"id", displayField:"code",
                 pickListWidth:250,
                 pickListProperties: {
                   showFilterEditor:true,
                   dataFetchMode:"local",
                   filterLocally:"true"
                 },
                 pickListFields: [             
                 {name:"name",title:"Departament"},
                 {name:"code",title:"Code", width:60}
              ]        
            }
    ]
    I've noticed that in my server request instead of getting the filter value in "department_id" I'm getting it in the displayField "code". I want to filter by value not by displayField.

    How can I get this right?



    Thanks in advance,
    John

    #2
    I've found another strange behaviour in:
    http://www.smartclient.com/#largeValueMapSQL

    I've entered "DO" in "Item Name" filter and got 2 request to the server one with criteria for itemName and one for itemID. Why does smartclient send for the second request (which, by the way it's useless) ?

    Thanks,
    John
    Attached Files

    Comment


      #3
      Both behaviors are already correct.

      First behavior: the user is typing in a value for the "code" field, not the ID field. So the criteria are correct.

      Second behavior - see formItem.fetchMissingValues.

      Comment


        #4
        Hello Isomorphic,

        When I change the displayfield of the combobox using:
        Code:
        listGridField.setDisplayField(displayField.getName());
        listGridField.setFilterEditorType(new ComboBoxItem());
        FormItem formItem = new FormItem(){{
        	setOptionDataSource(fkDatasource);
        	setDisplayField(fkDatasource.getTitleField());
        }};
        listGridField.setFilterEditorProperties(formItem);
        It sends the name of the displayfield of the ComboBoxItem in the criteria. I think this is a bug.

        Example:
        ListGridField displayField: itemName
        ComboBox displayField: name.
        Criteria is send using the value "name" and not the value "itemName".

        Comment


          #5
          This is correct behavior, see previous response:

          First behavior: the user is typing in a value for the "code" field, not the ID field. So the criteria are correct.

          Comment


            #6
            Maybe I am missing something, but I disagree. I understand your comments, but the user is typing a value for the displayfield of the listgridfield currently rendered. The ComboboxItem used for resolving this value should be considered a helper editor to resolve this value. The name of the displayfield of the listgridfield should therefore be used in the criteria.And not the name of the displayField of the ComboBoxItem (which is not the field being rendered by the listgridfield).

            Consider the following datasources:
            Shipment(partnerAddressId,partnerAddressName,customerAddressId,customerAddressName);
            Address(id,name)

            When I want to add a ComboBoxItem on the filtereditor for both customerAddressId and partnerAddressId (or better said, their displayField names; customerAddressName and partnerAddressName), I have to add two datasourcefields to the Address datasource (named partnerAddressName and customerAddressName).

            I can make a simple example to illustrate this if you need some more clarification.

            Comment


              #7
              Just show changes to a sample that cause the claimed problem. Also, be sure to report all the details the forum prompts you for.

              Comment


                #8
                I will show it using the example Large Value Map from the ee showcase:
                Added 2 fields to largeValueMap_orderItem:
                Code:
                <DataSource  
                    ID="largeValueMap_orderItem"  
                    serverType="sql"  
                    tableName="valMapOrderItem"  
                    testFileName="/ds/test_data/orderItem.data.xml"  
                >  
                    <fields>  
                        <field name="pk" type="sequence" primaryKey="true" hidden="true" />  
                        <field name="orderID" type="integer" />  
                        <field name="orderDate" type="date" />  
                //Changed
                        <field name="item1ID" type="integer" foreignKey="supplyItem.itemID" />  
                        <field name="item1Name" type="text" />  
                        <field name="item2ID" type="integer"  foreignKey="supplyItem.itemID"/>  
                        <field name="item2Name" type="text" />  
                        <field name="item3ID" type="integer"  foreignKey="supplyItem.itemID"/>  
                        <field name="item3Name" type="text" />  
                //End Change
                        <field name="unitPrice" type="float" />  
                        <field name="quantity" type="integer" />  
                    </fields>  
                // Some fetch to retrieve itemXName
                </DataSource>
                SypplyItem datasource:
                Code:
                    <DataSource  
                        ID="supplyItem"  
                        serverType="sql"  
                        tableName="supplyItem"  
                        titleField="itemName"  
                        testFileName="/ds/test_data/supplyItem.data.xml"  
                        dbImportFileName="/ds/test_data/supplyItemLarge.data.xml"  
                    >  
                        <fields>  
                            <field name="itemID"      type="sequence" hidden="true"       primaryKey="true"/>  
                //Changed
                            <field name="name"    type="text"     title="Item"        length="128"       required="true"/>  
                            <field name="item2Name"    type="text"     title="Item"        length="128"       required="true" valueXPath="name"/>  
                //End Changes
                            <field name="SKU"         type="text"     title="SKU"         length="10"        required="true"/>  
                            <field name="description" type="text"     title="Description" length="2000"/>  
                            <field name="category"    type="text"     title="Category"    length="128"       required="true"  
                                   foreignKey="supplyCategory.categoryName"/>  
                            <field name="units"       type="enum"     title="Units"       length="5">  
                                <valueMap>  
                                    <value>Roll</value>  
                                    <value>Ea</value>  
                                    <value>Pkt</value>  
                                    <value>Set</value>  
                                    <value>Tube</value>  
                                    <value>Pad</value>  
                                    <value>Ream</value>  
                                    <value>Tin</value>  
                                    <value>Bag</value>  
                                    <value>Ctn</value>  
                                    <value>Box</value>  
                                </valueMap>  
                            </field>  
                            <field name="unitCost"    type="float"    title="Unit Cost"   required="true">  
                                <validators>  
                                    <validator type="floatRange" min="0" errorMessage="Please enter a valid (positive) cost"/>  
                                    <validator type="floatPrecision" precision="2" errorMessage="The maximum allowed precision is 2"/>  
                                </validators>  
                            </field>  
                            <field name="inStock"   type="boolean"  title="In Stock"/>  
                            <field name="nextShipment"  type="date" title="Next Shipment"/>  
                        </fields>  
                    </DataSource>


                Code:
                public class LargeValueMapSQLSample implements EntryPoint {  
                  
                    public void onModuleLoad() {  
                        DataSource dataSource = DataSource.get("largeValueMap_orderItem");  
                        final DataSource feds = DataSource.get("supplyItem");  
                  
                        final ListGrid orderListGrid = new ListGrid();  
                        orderListGrid.setWidth(550);  
                        orderListGrid.setHeight(224);  
                        orderListGrid.setDataSource(dataSource);  
                        orderListGrid.setAutoFetchData(true);  
                        orderListGrid.setShowFilterEditor(true);  
                        orderListGrid.setCanEdit(true);  
                  
                        ListGridField orderIdField = new ListGridField("orderID");  
                // Changed
                        ListGridField item1IdField = new ListGridField("item1ID", "Item Name");  
                        itemIdField.setWidth("50%");  
                        itemIdField.setEditorType(new SelectItem());  
                        itemIdField.setFilterEditorType(new ComboBoxItem());  
                        itemIdField.setDisplayField("item1Name");  
                          
                        FormItem feProps = new FormItem() {{ setOptionDataSource(feds); }};  
                        itemIdField.setFilterEditorProperties(feProps);  
                
                        ListGridField item2IdField = new ListGridField("item2ID", "Item Name");  
                        item2IdField.setWidth("50%");  
                        item2IdField.setEditorType(new SelectItem());  
                        item2IdField.setFilterEditorType(new ComboBoxItem());  
                        item2IdField.setDisplayField("item2Name");  
                          
                        feProps = new FormItem() {{ setOptionDataSource(feds); }};  
                        item2IdField.setFilterEditorProperties(feProps);  
                
                        ListGridField item3IdField = new ListGridField("item3ID", "Item Name");  
                        item3IdField.setWidth("50%");  
                        item3IdField.setEditorType(new SelectItem());  
                        item3IdField.setFilterEditorType(new ComboBoxItem());  
                        item3IdField.setDisplayField("item3Name");  
                          
                        feProps = new FormItem() {{ setOptionDataSource(feds);
                setDisplayField("name"); }};  
                        item3IdField.setFilterEditorProperties(feProps);  
                // End changes 
                  
                        ListGridField quantityField = new ListGridField("quantity");  
                        ListGridField unitPriceField = new ListGridField("unitPrice");  
                  
                        orderListGrid.setFields(orderIdField, itemIdField, quantityField, unitPriceField);  
                  
                        orderListGrid.draw();  
                    }   
                }
                Input: Laptop
                Case filtering item1IdField: it will send a request using criteria name:
                item1Name startsWith 'Laptop'. This will result in an empty comboboxitem list because field item1Name is not found in supplyItem datasource.

                Case filtering item2IdField : it will send a request using criteria name:
                item2Name startsWith 'Laptop'. This will result in a filled comboboxitem list because field item2Name is found in supplyItem datasource. But I had to add a phantom item2Name (using valueXPath) to the supplyitem datasource.

                Case filtering item3IdField: it will send a request using criteria name:
                name startsWith 'Laptop'. Name is not a property of the largeValueMap_orderItem datasource and filtering will return errornous.

                Be aware: the fields itemXname are joined on a left join using a custom sql query.

                Using the displayField name of the ListGridField instead of the ComboBoxItem does not break the example! (itemName=itemName).

                Comment


                  #9
                  Looks like you may be doing more than you need to. Take a look at DataSourceField.includeFrom. This handles simple joins without customized SQL, including taking criteria against the field and handling the fact that it's actually in a different table.

                  Comment


                    #10
                    Hey Isomorphic,

                    That is a better setup indeed, I have implemented this, thanks. Still a problem remains:
                    I have a DS with two fields using the same foreignKey.
                    How can I include the name of both fields?
                    Code:
                    <DataSource  
                        ID="largeValueMap_orderItem">
                       <field name="item1" type="integer" foreignKey="supplyItem.itemID" />
                       <field name="item1Name" includeFrom="supplyItem.name"/>
                       <field name="item2" type="integer" foreignKey="supplyItem.itemID" />
                       // Is this the correct method ?? Seems like a clash with item1Name?
                       <field name="item2Name" includeFrom="supplyItem.name"/>
                    </DataSource>

                    Comment


                      #11
                      Right now, the includeFrom system can't do two joins to the same table on different FKs, so that second join has to be added via SQL Templating.

                      Comment

                      Working...
                      X