Announcement

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

    displayFormat doesnt work when canEdit="false"

    SmartGWTee 2.3

    I have a dynamicform displaying a datetime from a sql db using SmartGWT Server Framework. If canEdit="true" or not set as it is default. Then the date is formatted according to displayFormat

    <field name="dtEntry" type="datetime" displayFormat="toEuropeanShortDateTime" canEdit="false"></field>

    As soon as I set canEdit="false", I correctly get a read only field but the format is in default US format and not European Format aka dd-MM-yyyy hh:mm.

    I am assuming this is because the FieldItem type is different when canEdit="false" but I cant find any documentation on how to format a read only datetime like this. The workaround I am leaning toward is to format the datetime myself in a <selectclause> .

    Can anyone point me in the right direction?

    #2
    <field name="dtEntry" type="text" canEdit="false" customSelectExpression="cast(cast(datepart(dd, dtEntry) as varchar)+'-'+cast(datepart(mm, dtEntry)as varchar)+'-'+cast(datepart(yy, dtEntry)as varchar)+' '+cast(datepart(hh, dtentry)as varchar)+':'+cast(datepart(mi, dtEntry)as varchar)as varchar)"></field>

    This is now displaying the date time in my preferred format but it drops leading zeros in the minutes so more work to do. Would be nicer if I could plug in a function to format.

    Comment


      #3
      Using the following ds.xml the generated SQL is not correct. The orderby is being overridden by the outer select that generates rowids so regardless of the order by dtEntry the results are sorted by pkey, excuse the large piece of customSQL on the dtEntry field, this is because displayFormat does nto work with canEdit="false" so have to generate own formated date but need to sort by real date from sql table.

      Also note in the operation binding I have included the tableClause and whereClause as I was taking punts that by including the table or a whereclause the order by might magically work.

      Run over MSSQL 2008
      Generated SQL:
      Code:
      SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY x.pkey) AS rowID FROM (SELECT TOP 100 PERCENT  Note.Deleted, Note.pkey, Note.lNote, Note.patient_fkey, Note.comment, Note.Dismissed, Note.patientFile, Note.dtEntry, Note.SiteID, Note.isPopup, cast( case when datepart(dd, dtEntry) < 10 then '0'+ cast(datepart(dd, dtEntry) as varchar) else cast(datepart(dd, dtEntry) as varchar)end+     '-'+case when datepart(mm, dtEntry)<10 then '0'+ cast(datepart(mm, dtEntry)as varchar) else cast(datepart(mm, dtEntry)as varchar)end+     '-'+cast(datepart(yy, dtEntry)as varchar)+     ' '+ case when datepart(hh, dtentry)>12 and datepart(hh, dtentry)%12 > 9 then cast(datepart(hh, dtentry)%12 as varchar)        when datepart(hh, dtentry)>12 and datepart(hh, dtentry)%12 < 10 then '0'+ cast(datepart(hh, dtentry)%12 as varchar)when datepart(hh, dtentry) between 10 and 12  then cast(datepart(hh, dtentry) as varchar)else '0' + cast(datepart(hh, dtentry)as varchar)end +     ':'+ case when datepart(mi, dtEntry) <10 then '0'+cast(datepart(mi, dtEntry)as varchar) else cast(datepart(mi, dtEntry)as varchar) end     + case when datepart(hh, dtentry) > 11 then ' PM' else ' AM'end      as varchar) AS dateEntered, Note.PopUpColour FROM Note WHERE (Note.patient_fkey=73229) ORDER BY dtEntry) x) y WHERE y.rowID BETWEEN 1 AND 76
      Note.ds.xml

      Code:
      <!-- Auto-generated from database table Note -->
      
      <DataSource schema="dbo" dbName="SQLServer" tableName="Note"
      	ID="Note" dataSourceVersion="1"
      	generatedBy="SC_SNAPSHOT-2010-08-03/EVAL Deployment 2010-08-03"
      	serverType="sql">
      	<fields>
      		<field name="patient_fkey" type="number" hidden="true"></field>
      		<field name="pkey" type="number" primaryKey="true" hidden="true"></field>
      		<field name="lNote" type="number" hidden="true"></field>
      		<field name="dtEntry" type="datetime"></field>
      		<field name="dateEntered" type="text" canEdit="false"
      			customSelectExpression="cast( case when datepart(dd, dtEntry) &lt; 10 then '0'+ cast(datepart(dd, dtEntry) as varchar) else cast(datepart(dd, dtEntry) as varchar)end+
      				'-'+case when datepart(mm, dtEntry)&lt;10 then '0'+ cast(datepart(mm, dtEntry)as varchar) else cast(datepart(mm, dtEntry)as varchar)end+
      				'-'+cast(datepart(yy, dtEntry)as varchar)+
      				' '+ case when datepart(hh, dtentry)&gt;12 and datepart(hh, dtentry)%12 &gt; 9 then cast(datepart(hh, dtentry)%12 as varchar) 
      						when datepart(hh, dtentry)&gt;12 and datepart(hh, dtentry)%12 &lt; 10 then '0'+ cast(datepart(hh, dtentry)%12 as varchar)when datepart(hh, dtentry) between 10 and 12  then cast(datepart(hh, dtentry) as varchar)else '0' + cast(datepart(hh, dtentry)as varchar)end +
      				':'+ case when datepart(mi, dtEntry) &lt;10 then '0'+cast(datepart(mi, dtEntry)as varchar) else cast(datepart(mi, dtEntry)as varchar) end
      				+ case when datepart(hh, dtentry) &gt; 11 then ' PM' else ' AM'end
      				 as varchar)"></field>
      		<field name="comment" length="2500" type="text"></field>
      		<field name="SiteID" type="number" canEdit="false"></field>
      
      		<field name="PopUpColour" type="number">
      		</field>
      		<field name="Dismissed" type="boolean" hidden="true"
      			sqlStorageStrategy="integer"></field>
      		<field name="isPopup" type="boolean" detail="true"
      			sqlStorageStrategy="integer"></field>
      		<field name="patientFile" type="boolean" detail="true"
      			sqlStorageStrategy="integer"></field>
      		<field name="Deleted" type="boolean" hidden="true"
      			sqlStorageStrategy="integer"></field>
      	</fields>
      	<operationBindings>
      		<operationBinding operationType="fetch">
      			<tableClause>Note</tableClause>
      			<whereClause>$defaultWhereClause</whereClause>
      			<orderClause>dtEntry</orderClause>
      		</operationBinding>
      	</operationBindings>
      </DataSource>
      Last edited by aquajax; 26 Oct 2010, 06:46.

      Comment


        #4
        Hi Aquajax

        On the original problem. The issue is that canEdit="false" governs what type of formItem is used to display the date value. If canEdit is true, a dateItem is used, which supports 'displayFormat' specified as a date. If canEdit is false, a staticTextItem is used which does not.
        However all formItems support "dateFormatter" - try setting dateFormatter="toEuropeanShortDate" in your field definition.

        --
        UPDATE: On reflection this seems worth having. We've added support for "displayFormat" date, datetime and time type fields at the FormItem level. This fix will be present on the next nightly build. Let us know if you continue to see this problem
        Thanks
        Last edited by Isomorphic; 29 Oct 2010, 13:09.

        Comment


          #5
          Thanks Isomorphic team. Great service. So for anyone reading this you now can configure a datetime field in the ds.xml file and the read only field will display the correctly formatted date and time in my case
          <field name="dtEntry" sqlType="timestamp" type="datetime" displayFormat="toEuropeanShortDateTime" canEdit="false"></field>

          It would be nice to have more standard formats as this format does not include am pm at the end of the time as you can see from the screenshot.So while working through this I find I get a lot more control by implementing my own formatter as follows:
          Code:
          dynamicForm.getField("dtEntry").setValueFormatter(
          				new FormItemValueFormatter() {
          
          					@Override
          					public String formatValue(Object value, Record record,
          							DynamicForm form, FormItem item) {
          						DateTimeFormat formatter = DateTimeFormat
          								.getFormat("d/M/yy h:mm a");// TimeFormatter.TOSHORTTIME);
          						return formatter.format((Date) value);
          					}
          
          				});
          Unfortunately you cant do the same for a ListGrid as it doesnt have the setValueFormatter but it does have a setCellFormatter which you can probably fudge the same effect.

          Sorting issue also worked around by settign sortField to be the dtEntry field but not sure if this is optimal although in my case the number of rows does not require paging. I do consider the order by issue to be a bug and can provide further details if you want to pursue it further.
          Attached Files

          Comment

          Working...
          X