Null date column

9 posts, 1 answers
  1. Alison
    Alison avatar
    2 posts
    Member since:
    Jul 2012

    Posted 22 Feb 2013 Link to this post

    Hi

    I've done some searching but can't find a solution to this.

    Essentially, I have a settlement date column in my grid, however, this column can be null because the settlement date may not have been set yet.

    How do I show a date if there's a date entered, blank string if there's no date entered yet?

    I'm using JSON data in my datasource. I couldn't find a way to bring NULL dates in JSON so I'm currently bringing in the NULL dates as 01/01/0001 (which, by searching, seems to be the earliest date in JSON).

    My column at the moment is:
    columns: [
    { field: "SettlementDate", width: "150px", title: "Settlement Date", format: "{0:d/MM/yyyy}", filterable: { ui: "datetimepicker" } }
    ]
    I want to allow batch editing of the grid.

    Any suggestions or direction from someone who overcame a similar problem would be appreciated.

    Thanks, Alison
  2. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2895 posts

    Posted 25 Feb 2013 Link to this post

    Hi Alison,

    By default the grid will display empty string if the field has a null value. If in your case the data is not null, you may use a template with JavaScript expression to display a value according to your requirements. For example:
    { field: "date", template: "#= <condition> ? kendo.toString(date, 'd/MM/yyyy') : " " #" }

    Even though that the template will do the job, I recommend you to revise your server side implementation and return null instead of "01/01/0001". In this way you would be able to get the described behaviour out of the box.

    Regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Alison
    Alison avatar
    2 posts
    Member since:
    Jul 2012

    Posted 25 Feb 2013 Link to this post

    Thanks Alexander

    I managed to get the JSON to pass through a null.

    So, the .asmx file ended up...

    Public Class cDetail
        Public SettlementDate As DateTime?
    End Class
    <WebMethod> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
    Public Function getDetail() As cDetail()
        Dim items As New List(Of cDetail)
        .... omitted
        Using oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn").ToString())
            .... omitted
            Dim item As New cDetail()
            .... omitted
            Dim dteTemp As Date
            If (Date.TryParse(dr.Item("SettlementDate").ToString(), dteTemp) = True) Then
                item.SettlementDate = dteTemp
            End If
            .... omitted
        End Using
     
        Return items.ToArray()
    End Function

    I guess there's a lesson in there to not keep trying to get something to work last thing on a Friday - you tend to miss the obvious :).

    Regards, Alison

  4. Victor
    Victor avatar
    5 posts
    Member since:
    Jan 2013

    Posted 08 Mar 2017 in reply to Alexander Valchev Link to this post

    Is there a function that can encapsulate this logic "#= <condition> ? kendo.toString(date, 'd/MM/yyyy') : " " #"?  I have multiple values that need to check if it is null and it just seems that this logic can be called once and reused. 
  5. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    1263 posts

    Posted 09 Mar 2017 Link to this post

    Hi Victor,

    The columns.template option can be set to a function that takes the dataItem as an argument and returns the string to be rendered in the respective Grid cell, e.g.:

    http://dojo.telerik.com/EfIcU

    I hope this helps.

    Regards,
    Dimiter Topalov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  6. Victor
    Victor avatar
    5 posts
    Member since:
    Jan 2013

    Posted 09 Mar 2017 in reply to Dimiter Topalov Link to this post

    Thanks for the example.

    How can I get this same function to work in a Custom Template in an MVC Kendo Grid?  Here is a snippet of code.

     

    <div class='col-lg-4 col-md-4 col-sm-4'>
    <label class="tab-strip-label">Lot</label>
    <span class="tab-strip-span">#= LotNumber ==null ? "" : LotNumber #</span>
    </div>

    I want to do something like this and get an empty string.

    <div class='col-lg-4 col-md-4 col-sm-4'>
    <label class="tab-strip-label">Lot</label>
    <span class="tab-strip-span">#= ToString(LotNumber) #</span>
    </div>

  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 13 Mar 2017 Link to this post

    Hello Victor,

    I believe that what you are looking for is How to Apply Conditional Logic in Column Client Templates?

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  8. Victor
    Victor avatar
    5 posts
    Member since:
    Jan 2013

    Posted 15 Mar 2017 in reply to Boyan Dimitrov Link to this post

    I am looking to use a function in javascript similar to this c# method.

    public string GetValue(string e)
    {
                return (e == null) ? "" : e;
    }

    And in my client template I want to call it like this.

    <span class="tab-strip-span">#= GetValue(LotNumber) #</span>

    Instead of like this

    <span class="tab-strip-span">#= LotNumber ==null ? "" : LotNumber #</span>

     

     

  9. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 17 Mar 2017 Link to this post

    Hello Victor,

    Please refer to the Handle External Templates and Expressions and specifically take a look at the second example. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top