Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 123.8k

Render Id in anchor tag click datatable

Mar 21 2017 12:00 PM
Render Id in anchor tag click datatable.
Here is the code:
 
  1. 'columnDefs': [  
  2.           {  
  3.               targets: 2,  
  4.               render: function (data, type, row, meta) {  
  5.                   if (type === 'display') {  
  6.                       data = '<a href="/TicketTemplate/AppDetails/' + data["Id"] + '">' + data + '</a>';  
  7.                   }  
  8.   
  9.                   return data;  
  10.               }  
  11.           }  
  12.         ],  

How do i pass the row value on id.

i.e. pass like <a href="/TicketTemplate/AppDetails/@itm.Id">@itm.Title</a> on anchor tag click.

how do i get the id??

Here is the total code of datatable:

 
  1. $(document).ready(function ()  
  2. {  
  3.   debugger  
  4.     $('#TableId').DataTable(  
  5.     {  
  6.         //"columnDefs": [  
  7.         //    { "width": "5%", "targets": [0] },  
  8.         //    {  
  9.         //        "className": "text-center custom-middle-align",  
  10.   
  11.         //        "targets": [0, 1, 2, 3, 4, 5, 6]  
  12.         //    },  
  13.         //],  
  14.         'columnDefs': [{  
  15.             'targets': 0,  
  16.             'searchable'false,  
  17.             'orderable'false,  
  18.             'width''1%',  
  19.             'className''dt-body-center',  
  20.             'render': function (data, type, full, meta) {  
  21.                 return '<input type="checkbox">';  
  22.             }  
  23.         }  
  24.         ,  
  25.           {  
  26.               targets: 2,  
  27.               render: function (data, type, row, meta) {  
  28.                   if (type === 'display') {  
  29.                       data = '<a href="/TicketTemplate/AppDetails/' + data["Id"] + '">' + data + '</a>';  
  30.                   }  
  31.   
  32.                   return data;  
  33.               }  
  34.           }  
  35.         ],  
  36.         "language":  
  37.             {  
  38.                 "processing""<div class='overlay custom-loader-background'><i class='fa fa-cog fa-spin custom-loader-color'></i></div>"  
  39.             },  
  40.         "processing"true,  
  41.         "serverSide"true,  
  42.         "ajax":  
  43.             {  
  44.                 "url""/TicketTemplate/GetData",  
  45.                 "type""POST",  
  46.                 "dataType""JSON"  
  47.             },  
  48.         "columns": [  
  49.                    { "data"'' },  
  50.                     { "data""CreatedDate" },  
  51.                     { "data""Title" },  
  52.                      //{  
  53.                      //    //"data": "title",  
  54.                      //    "render": function (data, type, row, meta) {  
  55.                      //        //return '<a href=\"' + title + '\">' + title + '</a>';  
  56.                      //        return '<a href="' + title + '">' + data + '</a>';  
  57.                      //    }  
  58.                      //},  
  59.                       //{  
  60.                       //    //"data": "title",  
  61.                       //    "render": function (data, type, row, meta) {  
  62.                       //        //return '<a href=\"' + title + '\">' + title + '</a>';  
  63.                       //        return "<a href=" + row.myURL + "/" + row.id + "   id=" + row.id + ">" + row.Title + " </a>";  
  64.   
  65.   
  66.                       //    }  
  67.                       //},  
  68.   
  69.                     { "data""Name" },  
  70.                     { "data""Email" },  
  71.                     { "data""AssignTo" },  
  72.                     { "data""Status" }                    
  73.         ]  
  74.   
  75.   
  76.   
  77.   
  78.     });  
  79. });  
 

Answers (9)