How to make datatable row or cell clickable?

前端 未结 5 1531
梦谈多话
梦谈多话 2020-12-02 17:10

I\'m working on a history development of a particular user and I want it to be done with dataTables. However, I cannot find the way with which I can make my row or a particu

5条回答
  •  猫巷女王i
    2020-12-02 17:56

    First make sure you change the code of your dataTable initialization to save into a variable like this

    var oPatientMedicalHistory = $('#patient_medical_history').DataTable({
       //your stuff
    });
    

    Then you can assign a click event to all the rows like this

    EDIT: As Pointed out by Gyrocode.com, we should use delegated event handler as the tr's are created dynamically as we page. So The code should look like.

    $('#patient_medical_history tbody').on('dblclick','tr', function() {
        var currentRowData = oPatientMedicalHistory.row(this).data();
        // alert(currentRowData[0]) // wil give you the value of this clicked row and first index (td)
        //your stuff goes here
    });
    

    This must help you out.

提交回复
热议问题