How to pass dynamic value in columnDefs?

How to pass dynamic value in columnDefs?

shaileshnk101shaileshnk101 Posts: 1Questions: 1Answers: 0

var example = 0,1
"columnDefs": [ {
"searchable": false,
"orderable": false,
"targets": [0],
}
this is my block of code and I am trying to pass "var example" in targets
that would be look like this,
"targets": [example ]
plz help me to achive this.

This question has an accepted answers - jump to answer

Answers

  • DanFDanF Posts: 7Questions: 0Answers: 2
    Answer ✓

    These are 2 ways I do this stuff one way is to use columns and the other columnDefs.

    Good luck

     "columns": [
      { "data": "aaa" ,
        "render": function(data, type, full, meta) {
        aaa = data;
        data = 'http://some.webpage.com/ApplicationView/Index/'+data;
        return '<a href="'+data+'" target="_blank">'+aaa+'</a>';}
      },
      { "data": "bbb" },
      { "data": "ccc" },
      { "data": "ddd" },
      { "data": "eee" },
      { "data": "fff" },
      { "data": "ggg" },
      { "data": "hhh" }
     ],
     "columnDefs": [ {
      "targets": [1,2],
      "data": "url",
      "render": function ( data, type, full, meta ) {
       if (data === 'S1 ABCDEFG'){
        data = 'http://some.webpage.com:8080/something/';
        return '<a href="'+data+'" target="_blank">S1 ABCDEFG</a>';
       }
    
       source = data;
       data = 'http://webpage/application.aspx?myvalue='+data;
       return '<a href="'+data+'" target="_blank">'+source+'</a>';
       }        
      }]
    
This discussion has been closed.