tcode
tcode

Reputation: 5105

Display Empty String If Date Is NULL

I'm using JQuery Datatables and within one of the columns in my table I'm displaying dates. The problem is, some of the date data I'm passing to the column will be NULL and therefore displayed to the user within the table as 01/01/0001.

$('#dataTables-example').dataTable({

            "bServerSide": true,
            "sAjaxSource": "/Survey/GetAjaxData",
            "fnServerParams": function ( aoData ) {
                aoData.push( { "name": "id", "value": "40" }, 
                    { "name": "typeID", "value": "38" }
                    );
            },
            "bProcessing": true,
            "bJQueryUI": true,
            "aoColumns": [
                      null,
                      null, //Display Date Column
                      null,
            ]

        });

Is there any function/ code that can be added to my dataTable declaration above that will allow me to check if the data column contains value 01/01/0001 then instead display 'No Date' to the user?

Any help would be greatly appreciated with this.

Thanks.

Upvotes: 1

Views: 3821

Answers (1)

markpsmith
markpsmith

Reputation: 4918

I know this is a bit late, but I've just done this like so:

"aoColumns": [
                null,
                {
                  'mRender': function (data, type, full) {
                       if(full[1] != null){
                            // display date
                            return full[1];
                       }else{
                            return "No Date";
                      }
                   }
                }

Upvotes: 1

Related Questions