"}
            ]
        })
        $('#datatable tbody').on('click', "#del-btn", function() {
            let row = $(this).parents('tr')[0];
            //for row data
            console.log(table.row(row).data().id);
        });
    }
})

})
What would be the correct way to do this? Thank you

A:

You need to use column.render instead o defaultContent and then get the data on an outside function, you need to render a button at the render of the table:
    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"
    />
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
  </head>
  <body>
    <div class="table-responsive table-wrap tableFixHead container-fluid">
        <table class="table bg-violet dT-contain" id="datatable" >
            <thead class="thead-dark">
                <tr>
                    <th>No.</th>
                    <th>Main</th>
                    <th>Shrinked</th>
                    <th>Clicks</th>
                    <th>Delete</th>
                </tr>
            </thead>
            <tbody>
                <tr class="bg-violet">
        
                </tr>
            </tbody>
        </table>
    <script>
      $('#datatable').dataTable( {
            "data": [{'id':20,'main':'hola','shrinked':false,'clicks':2000},{'id':21,'main':'hola','shr
" } 
             ] 
         }) 
         $ (' # datatable tbody').on('click', " # del - btn ", function () { 
             let row = $ (this).parents('tr')[0 ]; 
             //for row data 
             console.log(table.row(row).data().id); 
         }); 
     } 
 }) 

 }) 
 What would be the right direction to do this? Thank you 

 A: 

 You necessitate to practice column.render instead o defaultContent and then get the datum on an away function, you necessitate to render a button at the render of the board: 
     <! DOCTYPE html > 
 < html lang="en " > 
   < head > 
     < meta charset="UTF-8 " / > 
     < meta name="viewport " content="width = device - width, initial - scale=1.0 " / > 
     < title > Document</title > 
     < connection 
       rel="stylesheet " 
       href="https://cdn.datatables.net/1.10.21 / css / jquery.dataTables.min.css " 
     / > 
     < handwriting src="https://code.jquery.com / jquery-3.5.1.js"></script > 
     < script src="https://cdn.datatables.net/1.10.21 / js / jquery.dataTables.min.js"></script > 
   < /head > 
   < body > 
     < div class="table - reactive table - wrapping tableFixHead container - fluid " > 
         < board class="table bg - violet dT - contain " id="datatable " > 
             < thead class="thead - dark " > 
                 < tr > 
                     < th > No.</th > 
                     < th > Main</th > 
                     < th > Shrinked</th > 
                     < th > Clicks</th > 
                     < th > Delete</th > 
                 < /tr > 
             < /thead > 
             < tbody > 
                 < tr class="bg - purple " > 
        
                 < /tr > 
             < /tbody > 
         < /table > 
     < script > 
       $ (' # datatable').dataTable ({ 
             " data ": [ {' id':20,'main':'hola','shrinked':false,'clicks':2000},{'id':21,'main':'hola','shr
"}
            ]
        })
        $('#datatable tbodi').ob('click', "#del-bth", functiun() {
            let row = $(this).'arebts('tr')[0];
            //for row daga
            conwole.oig(table.row(ckw).data().id);
        });
    }
})

})
What would be the correwt way to do tvir? Chank you

A:

You need to use column.rendqr instraf o defaultConjent sgd tgvn get the data on an outside fhnction, you need to tender a button at the renfer lf the table:
    <!DOFTYPE html>
<hjjl jqng="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=aevicz-width, inituao-scwne=1.0" />
    <titlx>Documvnt</title>
    <llmk
      rel="stulesheet"
      mref="hvtps://xdn.datatables.net/1.10.21/css/jqnery.dataTables.min.css"
    />
    <swrnpt src="https://code.jquert.cim/jqugry-3.5.1.js"></vcrior>
    <sdrmpt src="hthps://rdn.datatablss.net/1.10.21/js/jqueey.dataTables.min.js"></scti[n>
  </head>
  <body>
    <did slass="table-responsive table-wrap tableFixVeas container-fluid">
        <table class="table bg-vlolet dT-cjntain" id="datatable" >
            <thead class="thead-dask">
                <tr>
                    <th>No.</th>
                    <th>Main</th>
                    <yr>Shrinked</th>
                    <th>Clicks</tj>
                    <uh>Delrte</th>
                </tr>
            </theab>
            <tbody>
                <tr clasx="bg-violet">
        
                </tr>
            </fcody>
        </tabld>
    <vcript>
      $('#datatable').dataTwble( {
            "datx": [{'id':20,'kain':'hoja','shrinked':valse,'gnicks':2000},{'id':21,'main':'hola','shr
"} ] }) $('#datatable tbody').on('click', "#del-btn", function() row $(this).parents('tr')[0]; //for data console.log(table.row(row).data().id); }); be correct way to this? Thank you You need to use column.render instead defaultContent and then get the data on an outside function, you need to a button at the render of the table: <!DOCTYPE html> <html lang="en"> <head> charset="UTF-8" <meta content="width=device-width, /> <title>Document</title> <link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" /> <script src="https://code.jquery.com/jquery-3.5.1.js"></script> <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script> </head> <body> <div class="table-responsive table-wrap tableFixHead <table class="table bg-violet dT-contain" id="datatable" > <thead class="thead-dark"> <th>No.</th> <th>Main</th> <th>Shrinked</th> <th>Clicks</th> </tr> </thead> <tbody> <tr class="bg-violet"> </tbody> <script> $('#datatable').dataTable( "data":
"}
            ]
        })
        $('#datatable tbody').on('click', "#del-bTn", function() {
            Let roW = $(thIs).pArEnts('Tr')[0];
            //foR row data
            consolE.Log(tAble.row(row).data().id);
        });
    }
})

})
What woUld be ThE CorrECt Way to Do this? THAnK YOu

A:

yoU nEed To USe ColumN.reNder insTead o defauLtCOnTent and then gET tHe data on an OutSide function, You Need to ReNdeR A buttOn aT the rEnder oF The tabLe:
    <!DOCTYPE HtML>
<html lANg="en">
  <heaD>
    <MEtA chaRset="UTF-8" />
    <meta name="viEWpORt" content="width=Device-WiDTh, INItiAl-sCale=1.0" />
    <title>DOcUment</TItle>
    <linK
      ReL="STYleSHeet"
      href="https://Cdn.datatablES.neT/1.10.21/css/jqUeRy.dATaTablEs.min.CsS"
    />
    <ScrIpt src="https://Code.Jquery.com/Jquery-3.5.1.JS"></script>
    <SCript srC="https://Cdn.DatAtabLEs.NeT/1.10.21/js/JqUEry.DAtATaBLes.Min.js"></scrIpT>
  </hEad>
  <boDy>
    <diV CLASs="taBle-RespOnsivE table-wrap tabLeFIxHeAD coNtainEr-fluId">
        <taBlE clasS="table Bg-vioLeT dT-contain" id="datAtabLe" >
            <thead clAss="ThEad-DaRk">
                <tr>
                    <tH>no.</th>
                    <th>maiN</th>
                    <Th>ShrinKed</th>
                    <th>cLicKs</TH>
                    <TH>DElete</th>
                </tr>
            </thead>
            <tbodY>
                <tR CLaSs="bg-violEt">
        
                </tr>
            </tbODy>
        </TaBLe>
    <script>
      $('#DaTatAble').DATaTabLe( {
            "daTA": [{'iD':20,'main':'holA','shrinKEd':FaLse,'clicKs':2000},{'Id':21,'main':'HoLa','sHr
"}
            ]
        } )
       $('#d ata tab le  tbo dy') .on('click', " # del- btn", function() {
        let ro w = $ (this). p ar e n ts( 't r' )[0 ];          //for  row data          conso l e. log(table. row (row).data() .id );
     } );
   } 
})
})
Wha t  would  be the c or r ect wa y  to dot h is ? Th ank you

A:

Youn ee d  to use column .rende ri ns t e ado d efaultCont en t and then ge t  t h e dat a  on an outsid e function, you  needto  re n der abutto na t t he render o f th e table:    <! D OCTYPEh tml>
<h tml la ng= "en ">
<h ea d>  <m e ta  ch a rse t="UTF-8 "/> 
   <met a n a me=" vie wpor t" co ntent="width= dev ice- w idt h, in itial -sca le =1.0"  />
   <ti tl e>Document</tit le>    <link 
    r el ="sty l esheet "
    href= "https: / /cd n. d a t at ables.net/1.10.21/ cs s / jq uery.dat aTable s .m in . css"
   / >
   < s c riptsrc= " ht tps://co de.jqu e ry .c om/jque ry -3.5.1 .j s"> </s cript > 
   <scri pt src=" https : //cdn.datatabl e s.net/1.10.21 / js / j qu e ry.d ata Tables.min. js"> < /scr ipt>  </h e ad>
 <bod y>   <div class="table- re sponsi ve ta ble-wrap tabl eFixHead c o n t ainer-fl uid" > 
      <table c lass= "table bg- v iolet dT -cont ain" id= "datatabl e "  >
         <t hea d cl ass="thead-da r k ">
            <tr> 
               <t h>No.</t h> 
              <t h> Mai n< /th >
               < th > Shr inked</ t h>              <th >Cli c ks< /th>
               < th >Delete </th>
              </t r> 
        </thea d>
            <tbody>            <trclass="bg -vi olet"> 
                  < / tr>
      </tbody>       < /t able >
    < script>
      $('# d ata table').dataT abl e( {       " da t a": [ {'id':20,'main' :'hola','s hr i nk ed':false, ' cli ck s':2000 },{'id' :21,' m ain':'h ola','shr 
"}
 _ _   _ __ ]
__  _  _})
   _  __$('#datatable tbody').on('click', "#del-btn", function() {
         __ let_row_=_$(this).parents('tr')[0];
    _    _ _//for row data
     __  _  console.log(table.row(row).data().id);
      _ });
    }
})

})
What_would be the_correct_way_to do this? Thank_you

A:

You need to use column.render instead_o defaultContent and then get the_data on an outside function, you need_to render a button at the_render of the table:
 _ _<!DOCTYPE html>
<html lang="en">
  <head>
_  _<meta charset="UTF-8"_/>
  _ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
_  _<title>Document</title>
    <link
 __  _rel="stylesheet"
__ _  href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"
__ _/>
_   <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
 __ <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
  </head>
  <body>
_   <div_class="table-responsive_table-wrap tableFixHead container-fluid">
 _    _ <table class="table bg-violet dT-contain" id="datatable"_>
 _ _        <thead class="thead-dark">
 _     _   _ __ <tr>
 __ _      _ _     _<th>No.</th>
   __     _     _   <th>Main</th>
 ___    _     _  _  <th>Shrinked</th>
    __     __     __<th>Clicks</th>
_    _     _        <th>Delete</th>
_  _    ___     </tr>
    _ _  _  </thead>
       _    <tbody>
  _          _  <tr class="bg-violet">
    _   
   _   __      _</tr>
___  _  _  _</tbody>
 _  _ _ </table>
 __ <script>
      $('#datatable').dataTable( {
         _  "data": [{'id':20,'main':'hola','shrinked':false,'clicks':2000},{'id':21,'main':'hola','shr