Datatable function for specific column

transbetacism

I'm using DataTables to populate a table with results from a JSON request.

$.ajax({
  type: "POST",
  contentType: "application/json;",
  ...,
  success: function(data){

    var dataTblValues=$('#someTable').dataTable({
      "aaData": data.someList,
      "aoColumns": [
        {
          // Date
          "mData": "date"
        },
        {
          // Severity (I want some HTML output here depending on the severity)
          "mData": "severity"
        },
        {
          // Type
          "mData": "type"
        },
      ],
      "columnDefs" :[
        {
          "targets": 3,
          "data": null,
          "defaultContent": '<a href="#">Some link</a>'
        }
      ]
    });
  },
  error: function(data){
    console.log(data);
  },
});

What I want to do

The value of the second column ("Severity") is numeric, such as 1 or 2. Instead of just populating the value (1, 2 etc) directly in the column, I want to output something like:

<div class="severity-one">High</div>

...or

<div class="severity-two">Medium</div>

...depending on the severity.

How do I do this?

Gaurav Shah

for column 2 "severity"

"columnDefs" : [
                 {
                   "targets" : 1, // 1 because column count in dt starts from 0.
                   "render" : function(data, type, row) { 
                                      if(data==1) 
                                      { 
                                        return "<div class='severity-one'>High</div>"
                                      }

                                     if(data==2)
                                     {
                                       return "<div class='severity-two'>Medium</div>"
                                     }
                                                      }
                 }
              ]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to prevent row click function on specific column in datatable?

From Dev

Dropdown filter on specific column in DataTable

From Dev

Add a row under specific column in datatable

From Dev

Individual column searching on specific columns, DataTable

From Dev

datatable get specific column from row

From Dev

How to disable a search/filter on a specific column on a datatable?

From Dev

How to populate specific DataTable column with values

From Dev

Set value of each DataTable row in specific column

From Dev

Looping through a specific column from a datatable

From Dev

JQuery / Datatable set order By in specific column

From Dev

Get specific column foreach row in DataTable

From Dev

Get specific column header names from DataTable

From Dev

Define a specific column in a function

From Dev

Add text colour to a specific column name (header) in DT Shiny datatable

From Dev

How to get a specific column value from a DataTable in c#

From Dev

How to get one specific column from datatable into model in MVC Razor

From Dev

Sort a DataTable by a specific column rather than the primary key

From Dev

set reorderableColumn property to specific column of primeng datatable angular 2

From Dev

Add extra column in jquery Datatable after calling custom PHP function on it?

From Dev

Pass row ID of jquery datatable through column render to another function

From Dev

pandas DataFrame, how to apply function to a specific column?

From Dev

rollapply function on specific column of dataframes within list

From Dev

function to subtract each column from one specific column in r

From Dev

Can't hide column in jquery datatable shows TypeError: table.column is not a function

From Dev

How can I add filteration drop down on a specific column in datatable plugin along with searching and sorting

From Dev

How do I manipulate data from a specific column in a databound datatable in .net

From Dev

In a DataTable object, how do I store an array of strings in each cell of a specific column?

From Dev

Scroll to specific row in DataTable

From Dev

Count specific datatable columns

Related Related

  1. 1

    How to prevent row click function on specific column in datatable?

  2. 2

    Dropdown filter on specific column in DataTable

  3. 3

    Add a row under specific column in datatable

  4. 4

    Individual column searching on specific columns, DataTable

  5. 5

    datatable get specific column from row

  6. 6

    How to disable a search/filter on a specific column on a datatable?

  7. 7

    How to populate specific DataTable column with values

  8. 8

    Set value of each DataTable row in specific column

  9. 9

    Looping through a specific column from a datatable

  10. 10

    JQuery / Datatable set order By in specific column

  11. 11

    Get specific column foreach row in DataTable

  12. 12

    Get specific column header names from DataTable

  13. 13

    Define a specific column in a function

  14. 14

    Add text colour to a specific column name (header) in DT Shiny datatable

  15. 15

    How to get a specific column value from a DataTable in c#

  16. 16

    How to get one specific column from datatable into model in MVC Razor

  17. 17

    Sort a DataTable by a specific column rather than the primary key

  18. 18

    set reorderableColumn property to specific column of primeng datatable angular 2

  19. 19

    Add extra column in jquery Datatable after calling custom PHP function on it?

  20. 20

    Pass row ID of jquery datatable through column render to another function

  21. 21

    pandas DataFrame, how to apply function to a specific column?

  22. 22

    rollapply function on specific column of dataframes within list

  23. 23

    function to subtract each column from one specific column in r

  24. 24

    Can't hide column in jquery datatable shows TypeError: table.column is not a function

  25. 25

    How can I add filteration drop down on a specific column in datatable plugin along with searching and sorting

  26. 26

    How do I manipulate data from a specific column in a databound datatable in .net

  27. 27

    In a DataTable object, how do I store an array of strings in each cell of a specific column?

  28. 28

    Scroll to specific row in DataTable

  29. 29

    Count specific datatable columns

HotTag

Archive