Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatable with html content

I am using jquery datatable and data input injson format.

$('#newItemBasketTab').dataTable({
  "aaData": result.itembasketdata,
  "aoColumns": 
  [
     {"mDataProp": "nic5dcodename"},
     {"mDataProp": "asiccprodcodename"},
     {"mDataProp": "unit_name"},
     {"mDataProp": "prod_quantity"},
     {"mDataProp": "prod_value"}
  ]
});

Now I want to place a checkbox in first column of datatable and based on an ID field in json data, the checkbox needs to be checked or unchecked. Is it possible to add html content to datatable?

like image 655
Thara Avatar asked Feb 28 '26 21:02

Thara


1 Answers

You code will look like,

$('#newItemBasketTab').dataTable({
  "aaData": result.itembasketdata,
  "aoColumns": 
  [
     {"mDataProp": "Selection", 
      "fnRender":function(obj, type){
                   if(obj.aData['ID'])
                        return "<input type='checkbox' checked='checked'>"
                   else
                        return "<input type='checkbox'>"
                 }
     }
     {"mDataProp": "nic5dcodename"},
     {"mDataProp": "asiccprodcodename"},
     {"mDataProp": "unit_name"},
     {"mDataProp": "prod_quantity"},
     {"mDataProp": "prod_value"}
  ]
});

You can add any html code that you want to display in fnRender function

like image 107
Amar Kamthe Avatar answered Mar 03 '26 09:03

Amar Kamthe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!