We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Replace null default values with a default string

Thread ID:

Created:

Updated:

Platform:

Replies:

127681 Dec 2,2016 04:37 AM Dec 12,2016 12:43 AM JavaScript 3
loading
Tags: ejGrid
Stephen Abel
Asked On December 2, 2016 04:37 AM

Hi,

In a grid control I receive a nullable date field. For the null values, rather than just displaying a blank cell, is there a way of setting a default value so it could display something like 'No date supplied' instead?

Thanks,

Steve

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On December 5, 2016 08:44 AM

Hi Stephen, 
 
You can use the queryCellInfo event of the Grid to modify any cells in the Grid. Therefore, for a null date values, you can use the queryCellInfo event and format the cells.  
Based on the type of the column and values present in the current cell, text of the particular has been replaced. Refer to the following code example and API Reference. 
 
<div id="Grid"></div> 
<script type="text/javascript"> 
    $(function () { 
        var data = [ 
            { OrderID: 10248, OrderDate: new Date() }, 
            { OrderID: 10249, OrderDate: null }, 
            { OrderID: 10250, OrderDate: "" } 
        ] 
        $("#Grid").ejGrid({ 
            dataSource: data, 
            allowPaging: true, 
            queryCellInfo: function (args) { 
                if (args.column.type == "date" || args.column.type == "datetime") { 
                    var val = ej.getObject(args.column.field, args.data); 
                    if (ej.isNullOrUndefined(val) || val == "") 
                        $(args.cell).text("No Date Supplied"); 
                } 
            }, 
            columns: [ 
                { field: "OrderID" }, 
                { field: "OrderDate", format: "{0:MM/dd/yyyy}" } 
            ], 
        }); 
    }); 
</script> 
 
  
 
We have prepared a sample that can be referred from the following jsPlayground. 
 
 
Regards, 
Seeni Sakthi Kumar S. 


Stephen Abel
Replied On December 8, 2016 07:46 AM

Thank you - that is exactly what I was looking for.

Mohammed Farook J [Syncfusion]
Replied On December 12, 2016 12:43 AM

Hi Stephen, 
  
Thanks for updated. 
  
Regards, 
J.Mohammed Farook 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;