How to search and display with render

How to search and display with render

peruanersperuaners Posts: 3Questions: 1Answers: 0

Hi!
Can anyone help me with a string to search and display all numbers in a column that starts with a zero. Attached code is ok but just search and displays the specific number, otherwise it displays an url in that row.

"columnDefs": [ {
"targets": 7,
"data": "book",
"render": function ( data, type, full, meta ) {
return data == '0156' ? '0156' : '<a href="'+data+'">Book online</a>';
}
} ]

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,108Questions: 90Answers: 429
    edited April 2017 Answer ✓
    columns: [ 
         {   data: "book",
             render: function ( data, type, row ) {
                  if (row.book.substring(0,1) == '0') {
                      return row.book;
                   } else {
                      return '<a href="'+row.book+'">Book online</a>';
                   }
               }    
           }
     ]
    
  • peruanersperuaners Posts: 3Questions: 1Answers: 0

    Thanks rf1234! Works like a charm. :)

This discussion has been closed.