Announcement

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

    Datetime items in listgrids ignore the time part.

    When trying to use a datetime item in a listgrid the time part seem to get ignored. I tried this on the latest nightly (SmartClient Version: v8.2p_2012-07-09/PowerEdition Deployment (built 2012-07-09)) with FireFox 11.

    When I only change the time part of the datetime no update is sent to the server. When I change the date part this is noticed.

    I create my listgrid like this:

    Code:
    public class DateTimeTest implements EntryPoint {
    	
    	public void onModuleLoad() {
    		DataSource ds = DataSource.get("Customer");
    		
    		ListGrid listGrid = new ListGrid();
    		listGrid.setAutoFetchData(true);
    		
    		ListGridField dateTimeField = new ListGridField("cstm_modifiedOn", "Modified On");
    		dateTimeField.setType(ListGridFieldType.DATE);
    		dateTimeField.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATETIME);
    	
    		dateTimeField.setEditorType(new DateTimeItem());
    		
    		listGrid.setFields(dateTimeField);
    		listGrid.setDataSource(ds);
    		listGrid.setAutoFetchData(true);
    		listGrid.setHeight(500);
    		listGrid.setWidth(500);
    		listGrid.setCanEdit(true);
    		listGrid.draw();
    		
    	}
    }
    This is my datasource:

    Code:
    <DataSource 
    	serverType="sql"
    	dbName="Mysql"
    	tableName="Customer"
    	ID="Customer"
    >
    	<fields>
    		<field primaryKey="true" type="sequence" name="cstm_pk" hidden="false"></field>
    		<field type="text" length="45" name="cstm_name" ></field>
    		<field type="datetime" name="cstm_modifiedOn" ></field>
    	</fields>
    </DataSource>

    #2
    You need to set the input format to match your formatter.
    Last edited by Isomorphic; 9 Jul 2012, 07:47.

    Comment


      #3
      I must be missing something

      When I use
      Code:
      DateTimeItem editorType = new DateTimeItem();
      		editorType.setUseTextField(true);
      		editorType.setUseMask(true);
      		editorType.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATETIME);
      		editorType.setInputFormat("DMY");
      		dateTimeField.setEditorType(editorType);
      I get a validation error in the grid "must be a date". The same happens when i use DateUtils.setInputFormat. When i use DateUtil.setDateParser or DateUtil.setDateInputFormatter these do not get called.

      Is there a possibility to add ListGridFieldType.DATETIME? Since DateTimeItems exist and in the datasource there is FieldType.DATETIME I think this would be a logical addition

      Comment


        #4
        Just remove your call to setType() - this isn't needed, the ListGrid already knows the field is datetime because of the DataSource. When you call setType("date"), predictably this causes time portions to be ignored.

        It's true there should be a datetime value in the enum for cases where there isn't a DataSource, we'll correct this. setAttribute("type", "datetime") can be used to set this, but again, it's not necessary for you.

        Comment


          #5
          Thanks, that was indeed the problem

          Comment

          Working...
          X