[CLOSED] Dates & Json & ComboBoxes

  1. #1

    [CLOSED] Dates & Json & ComboBoxes

    Hi,

    I have a view that renders a list of dates in a ComboBox. I want to controll how that dropdown renders those dates, so I do this:

    <ext:ComboBox ID="ResultsSetCombo" runat="server" FieldLabel="Patching Result Set"
            Editable="false" DisplayField="CreationDate" ValueField="FrontEndMappingSetId" TypeAhead="false"
            Mode="Local" DataIndex="FrontEndMappingSetId" Width="500" SelectedIndex="0" ItemSelector="div.list-item">
            <Store>
                <ext:Store ID="FrontEndMappingResultsStore" runat="server" AutoLoad="true">
                <Reader>
                    <ext:JsonReader IDProperty="FrontEndMappingSetId">
                        <Fields>
                            <ext:RecordField Name="FrontEndMappingSetId" />
                            <ext:RecordField Name="CreationDate" Type="Date"/>
                        </Fields>
                    </ext:JsonReader>
                </Reader>            
                </ext:Store>
            </Store>
            <Template runat="server">
                <Html>
                    <tpl for=".">
                        <div class="list-item">{CreationDate:date("d-M-Y H:i:s")}</div>
                    </tpl>
                </Html>
            </Template>
            <Listeners>
                <AfterRender Fn="onAfterRender" />
                <Select Fn="onSelect" />
                <Blur Fn="onBlur" />
            </Listeners>
        </ext:ComboBox>
    The problem is, while the items in the dropdown render as I want, the SELECTED item has the default rendering, and for some reason it's getting the time wrong. For example if the time is 17:00 (5pm), it shows as 05:00. I'm loading the combo from data I'm loading the combo's store from JSON loaded in the controller:

                ViewBag.MappingResultSets = JSON.Serialize(mappingResultSets.OrderByDescending(r => r.CreationDate).Select(c => new { c.FrontEndMappingSetId, c.CreationDate }));
    And here is a snippet of the JSON

    {"FrontEndMappingSetId":25,"CreationDate":"2012-05-22T14:30:39.373"},{"FrontEndMappingSetId":24,"CreationDate":"2012-05-16T14:12:11.883"}
    Is this correct? I tried using the default "JavascriptSerializer" which then formats the dates in that /Date()/ Format, but that doesn't seem to work at all.
    Last edited by Daniil; May 24, 2012 at 2:49 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I managed to fix this by adding this code to the onSelect and onBlur events on the combo (not sure if this was the best way):

    
            var onSelect = function (combo, record, index) {
                this.setRawValue(Ext.util.Format.date(record.get("CreationDate"), "d-M-Y H:i"));
                MappingResultsStore.reload();
    
            }
    
            var onBlur = function () {
                this.setRawValue(Ext.util.Format.date(this.getRawValue(), "d-M-Y H:i"));
            }
    Thanks, you can mark as closed :)
  3. #3
    Hi,

    Your solution with onSelect looks good.

    But I'm not sure you need onBlur as there is
    Editable="false"
    Please clarify what scenario does onBlur make sense?
  4. #4
    Quote Originally Posted by Daniil View Post
    Hi,

    Your solution with onSelect looks good.

    But I'm not sure you need onBlur as there is
    Editable="false"
    Please clarify what scenario does onBlur make sense?

    Hi yes you are right the onBlur was not needed, thanks :)

Similar Threads

  1. Replies: 10
    Last Post: Aug 01, 2011, 1:58 PM
  2. [CLOSED] Dates Between
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 28, 2011, 9:31 PM
  3. Replies: 3
    Last Post: May 11, 2010, 4:47 AM
  4. [CLOSED] [1.0]ComboBox and Dates
    By bethc in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 23, 2010, 4:37 AM
  5. [CLOSED] Dates
    By Ben in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 07, 2009, 6:14 PM

Posting Permissions