Mr.Human
Mr.Human

Reputation: 617

Jquery Datatable - Passing value from one "Data" element to another

I'm using the JQuery datatable. I have made the first column of the table, which is RequestNo, as clickable.

Consider the following script :

  "ajax":
     {
         "url": "/Request/Search/LoadData",
         "type": "POST",
         "datatype": "json",
         "data": function (d) {
             d.obj = searchFilters();
         },
      },

     "columns":
     [
             {
                 "data": "RequestNo",
                 "render": function (data, type, full, meta) {
                      //if Status=="Draft"
                     {return '<a href="/Request/Request?RequestId=' + data + '">' + data + '</a>';}
                  else{//return to some another another link}
                 }
             },
             { "data": "Status" }  // this value is the deciding factor

What I want to do is: -If the value returned for Status is "Draft" then, if the RequestNo field is clicked in the UI, it should return to the URL mentioned in the above IF Block.. -Else if the value is other than "Draft" then it should return to another URL

What I'm unable to do is to pass the value of Status to the above specified function in "render"

Can anyone tell me how can I pass the value of Status to the function in the "render" of RequestNo?

Thanks in advance.

Upvotes: 2

Views: 1441

Answers (1)

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14604

You can pass row to function and get value for status

"render": function (data, type, row,full, meta) {
           if(row.Status=="Draft")
           {
             return '<a href="/Request/Request?RequestId=' + data + '">' + data + '</a>';
           }
           else{
             //return to some another another link}
               }

Also i think you need row.RequestNo instead of data here ?RequestId=' + data + '"

Upvotes: 2

Related Questions