Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

use response data in columndef datatable jquery

I am using datatable jquery.I want to use Sr_no in data-id of td tag but How to get data of Sr_no.

or you can say that I want particular data from data reponse

I have highlighted in code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$("#fir").dataTable({
    "bProcessing": true,

    "sAjaxSource": "paid.php",
    "sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
    "sPaginationType": "full_numbers",
    "aoColumns": [

        {"mData": "Sr_no"}, <------ I dont want to add this column in table but I want to use value
        {"mData": "Category_Name"},
        {"mData": "Vendor_Name"},
        {"mData": "date"},
        {"mData": "Price"},
        {"mData": "Payment_Mode"},
        {"mData": "remark"},
        {"mData": "edit"},
        {"mData": "cancel"}
    ],
    'columnDefs': [
        {
           'targets': 1,
           'createdCell':  function (td, cellData, rowData, row, col) {
               console.log(row,col);
              $(td).attr('data-id',Sr_no);  <----------------
           }
        }

     ]

});



>Solution :

You can use rowData.Sr_no to get the value of Sr_no for each row. Change targets: 1 to

{
   'targets': 1,
   'createdCell':  function (td, cellData, rowData, row, col) {
       console.log(row,col);
      $(td).attr('data-id', rowData.Sr_no);
   }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading