Click event of button in datatables does not work

Click event of button in datatables does not work

aadewojoaadewojo Posts: 9Questions: 5Answers: 0
edited October 2014 in Free community support

Hi Everyone,
I have a datatable that is automatically populated(via ajax) when a button is clicked. Each row of the table has child row and they all work well. I have two buttons in the datatable that is also well rendered, however on the click of one of the button, I like to get the data in the row of that button, but it gives me error saying "myTable.fngetData" ia not a function. please find below my code

          $(    function(){ 

    $( "#buttonShowtContract" ).click(function () {

         nDays = $("#dLength").val();
        var myTable =  $('#terminalTable').DataTable( {
        //"destroy": true,
        "bProcessing": true,
        //"bServerSide": true,
        "sAjaxSource": "terminatecontractList.php",
         "fnServerParams": function ( aoData )   
              {  
                  aoData.push( { "name": "nDays", "value": nDays } );  

              },

         "aoColumns": [
                 {

            "class":          'details-control',
                    "orderable":      false,
                    "mData":           null,
                    "defaultContent": ""
                },

                { "sName": "CustName","mData": "CustName" },
                { "sName": "SupplierName","mData": "SupplierName" },                    
            { "sName": "TermDate","mData": "TermDate" },
            { "sName": "EndDate","mData": "EndDate" },
            { "mData": "ContractReference",
              "mRender": function ( data, type, full ) {
              return '<button type=\"button\" id = \"'+data+'\" name=\"'+data+'\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#custModal\">Review Email</button>';
                 }},
                { "mData": "ContractID",
              "mRender": function ( data, type, full ) {
            return '<button type=\"button\" id = \"'+data+'\" name=\"'+data+'\" class=\"btn btn-primary try\">Terminate</button>';
                 }
        }

        ]
     } );

        $('#terminalTable tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = myTable.row( tr );

            if ( row.child.isShown() ) {
                // This row is already open - close it
               //var T =  fillSmall(d);
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                // Open this row
                row.child( format(row.data()) ).show();
                tr.addClass('shown');
            }
        } );


        $('#terminalTable tbody').on('click', '.try', function () {
        alert( 'update' ); // works
         var rowData=  myTable.fnGetData( this )
            console.log("rowData: " + rowData[0]);                   
        });

    });



    }); //end of function call

Answers

  • kaka2kkaka2k Posts: 1Questions: 0Answers: 0

    I am having the same issue.

  • aadewojoaadewojo Posts: 9Questions: 5Answers: 0

    uhm. An have you found a solution, because I haven't found any yet and nobody has replied me with an answer. its unfortunate.

This discussion has been closed.