Announcement

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

    How to get multiple field as comma separated values in grid column?

    Hi,
    I need some help in the following scenario:
    I would like to get the grid column filled with comma separated list of validFrom dates for each person like on this picture:
    Click image for larger version

Name:	multiple0.png
Views:	108
Size:	4.3 KB
ID:	244750

    Person.xml data looks like:
    Code:
    <response>
        <data>
            <Person>
                <id>351</id>
                <code>michalg</code>
                <certificate>
                    <Certificate>
                        <id>535</id>
                        <certificateType>
                            <id>521</id>
                            <code>pisanie na klawiaturze</code>
                        </certificateType>
                        <validFrom>2017-05-19</validFrom>
                        <issuedBy>komisja nadzoru biurowcow</issuedBy>
                        <documentNo>abcd321</documentNo>
                    </Certificate>
                    <Certificate>
                        <id>34383</id>
                        <certificateType>
                            <id>521</id>
                            <code>pisanie na klawiaturze</code>
                        </certificateType>
                        <validFrom>2017-05-20</validFrom>
                        <issuedBy>komisja nadzoru programistow</issuedBy>
                        <documentNo>qwerty123_pl</documentNo>
                    </Certificate>
                    <Certificate>
                        <id>533</id>
                        <certificateType>
                            <id>521</id>
                            <code>pisanie na klawiaturze</code>
                        </certificateType>
                        <validFrom>2017-05-21</validFrom>
                        <issuedBy>komisja nadzoru programistow</issuedBy>
                        <documentNo>qwerty123</documentNo>
                    </Certificate>
                    <Certificate>
                        <id>34382</id>
                        <certificateType>
                            <id>521</id>
                            <code>pisanie na klawiaturze</code>
                        </certificateType>
                        <issuedBy>komisja nadzoru programistow</issuedBy>
                        <documentNo>qwerty123_en</documentNo>
                    </Certificate>
                </certificate>
            </Person>
        </data>
        <requestedDataSource>Person</requestedDataSource>
        <status>STATUS_SUCCESS</status>
    </response>
    I am using the following test code:
    Code:
    package pl.com.tech4.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.OperationBinding;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.AutoFitWidthApproach;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.DSOperationType;
    import com.smartgwt.client.types.DSProtocol;
    import com.smartgwt.client.widgets.grid.ListGrid;
    
    public class MainEntryPoint implements EntryPoint {
      
        @Override
        public void onModuleLoad() {
    
            layout();
        }
      
        private void layout() {
    
            DataSource personDS = new DataSource();
            personDS.setID("Person");
            OperationBinding fetchBinding = new OperationBinding();
            fetchBinding.setOperationType(DSOperationType.FETCH);
            fetchBinding.setDataFormat(DSDataFormat.XML);
            fetchBinding.setDataProtocol(DSProtocol.POSTXML);
            personDS.setOperationBindings(fetchBinding);
            personDS.setDataURL("Person.xml");
          
            DataSourceField idField = new DataSourceField();
            idField.setName("id");
            idField.setPrimaryKey(true);
            idField.setHidden(true);
           
            DataSourceTextField codeField = new DataSourceTextField();
            codeField.setName("code");
    
            DataSourceField certificate_validFromField = new DataSourceField();
            certificate_validFromField.setName("certificate_validFrom");
            certificate_validFromField.setValueXPath("certificate/Certificate/validFrom");
            certificate_validFromField.setMultiple(true);
            //can not get comma separated list of dates without the following line:
            //certificate_validFromField.setTypeAsDataSource(new DataSource());
    
            personDS.setFields(idField, codeField, certificate_validFromField);
           
            ListGrid lg = new ListGrid();
            lg.setDataSource(personDS);
            lg.setAutoFetchData(true);
            lg.setAutoFitFieldWidths(true);
            lg.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
            lg.setWidth(300);
            lg.draw();
        }
      
    }
    Although I am using multiple=true attribute of certificate_validFromField and the proper xpath="certificate/Certificate/validFrom", I got only one first date displayed:
    Click image for larger version

Name:	multiple1.png
Views:	91
Size:	3.9 KB
ID:	244751
    But if I uncomment the line:
    Code:
            certificate_validFromField.setTypeAsDataSource(new DataSource());
    then I got dates as comma separated list as desired.
    For sure this is not the right way to go, as it brakes other things - I am not able to get comma separated list of dates any other way.
    What am I missing here?
    Thanks,
    MichalG

Working...
X