Can we use regex on the column?

Can we use regex on the column?

phavanagiphavanagi Posts: 13Questions: 5Answers: 0
edited July 2017 in Free community support

Hi,

I have a column named EffectiveDate.
The data is something like: "2017-07-07T00:00:00" I want to just display it as 07-07-2017 and not the time. Can we use regex to solve this?

I have columns as:

columns: [

                        { "data": "EffectiveDate" },
                        { "data": "Id" }
                  ] 

Can I use regex in {"data" : "EffectiveDate"."some relevant regex"} or is there any other way?

Thanks!

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    I have a better suggestion. Use moment.js to format the given date to what you want.
    with:

     <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
    
    

    I did the rendering in the columnDefs but you could do it in the columns

    http://live.datatables.net/buzibuho/1/edit

    $(document).ready( function () {
      var table = $('#example').DataTable(
        {columnDefs:[{targets:4, render:function(data){
          var mDate = new moment(data);
          if(mDate.isValid()){
          return mDate.format("DD/MM/YYYY");
          }
          else{
            return "";
          }
          
         }}]}
      );
    } );
    
  • bindridbindrid Posts: 730Questions: 0Answers: 119

    http://momentjs.com/ is the site. Its a fairly popular library.

  • phavanagiphavanagi Posts: 13Questions: 5Answers: 0

    @bindrid , Yes, I did something similar using render and it works.. Thanks!

This discussion has been closed.