Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use jQuery DataTable in my ASP.NET MVC project. One of my databasecolumns gives true/false values. I want to translate its value to a string and changes its color. I tried following code for this column:

"columns": [
                              {"data":"pmId"},
                              {"data":"pmNumber"},
                              {"data":"costCenter"},
                              {"data":"serviceType"},
                              {"data":"destination"},
                              {"data":"workCenter"},
                              {"data":"creationDate"},
                              {"data":"creationTime"},
                              {"data":"startDate"},
                              {"data":"endDate"},
                              {"data":"mainFileName"},
                              {"data":"returnDate"},
                              {"data":"returnTime"},
                              {"data":"status"},
                              {"data":"fileName"},
                              {"data":"uploader"},
                              {
                                  "data":"isDownloaded",
                                  "render": function(data){
                                      if(data == true){
                                          "display": "Downloaded"
                                      }else{
                                          "display": "Not Downloaded"
                                      }
                                  }
                              },
                              {
                                "render": function(data, type, full, meta) { return '<a class="btn btn-info" href="/DemoGrid/Edit/' + full.CustomerID + '">Edit</a>'; }
                              },
                              {
                                data: null,
                                render: function(data, type, row) {
                                return `<a href='#' class='btn btn-danger' onclick="DeleteData('${row.pmId}', '${row.mainFileName}', '${row.fileName}')";>Delete</a>`;
                                 }
                              }
                           ],


The problem is that it does not work.

What I have tried:

I used the following code:

{
                                  "data":"isDownloaded",
                                  "render": function(data){
                                      if(data == true){
                                          "display": "Downloaded"
                                      }else{
                                          "display": "Not Downloaded"
                                      }
                                  }
                              },
Posted
Updated 28-Jan-22 7:28am

1 solution

Not sure what datatype is coming into your data object. First thing you need to check the data coming in your response.
Secondly, You are checking with irrespective of the datatype of variable. If you are sure the data is boolean in response then check strict type like:
if(data === true){
    "display": "Downloaded"
}else{
    "display": "Not Downloaded"
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900