Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
How to format a date in a multi-column combobox
posted

I have a jQuery combobox in which I want to display a name column and a date column.  

 

@(Html

    .Infragistics()

    .Combo()

    .ID("comboEvents")

    .FilteringType(ComboFilteringType.None)

    .ValueKey("eventId")

    .TextKey("name")

    .DropDownMinHeight(50)

    .Width("300px")

    .DataSource(Url.Action("EventListCombo"))

    .ItemTemplate("<div>${name} (${date})</div>")

    .DataBind()

    .Render()

)

 

Obviously the date shows up as a JSON date ("/Date(1315540800000)/").  How can I get the jQuery date format to work within the above itemtemplate?

Parents
  • 6279
    Suggested Answer
    posted



    psurobdude said:
    Obviously the date shows up as a JSON date ("/Date(1315540800000)/").  How can I get the jQuery date format to work within the above itemtemplate?


    Hi Josh,

    As JoshNoe suggested, you will need to parse the serialized date from the server response.

    What I can recommend is to use a simple function for this task - for example:

    var parseToDate = function(val) {
         return new Date(parseInt(val.replace('/Date(', '').replace(')/', ''), 10));
    };


    And if you want to format the dates you have just like the grid does, you will need to do this yourself as we don't provide it as an out of the box.
    I'm partially lying to you here, because if you dig into the code of the igGrid, you will see that in order to apply column formatting, the igGrid relies on a function called $.ig.formatter() - it's defined in the ig.util.js file and is meant to be internal, but I don't see a reason why you shouldn't use it.

    Basically the  $.ig.formatter() function is easy to use, because all you need is to call it with the first 3 parameters:  

    1. the value that has to be formatted
    2. the type of the data (this corresponds to an igGrid column's dataType)
    3. the format that you wish to apply  - you can pick from the values, available for the column format of the igGrid:

     

      

     

    I've attached an HTML sample page to this reply which illustrates my suggestion.
    Hope it helps you out1.

    Cheers and good luck!
    Borislav 

    t68646.zip
Reply Children