Binding click event with tr elements in jQuery Datatable on () not working

I am developing a table that will contain all of our users, which can also be changed by clicking on tablerow and editing the data in a form that opens after clicking a click.

If I have all the users loaded when the page loads, my code works fine.

As soon as I change my datatable to load users when initializing data, it will only work on the first page.

If I uncomment the bottom of mine ready(function())and delete fnInitComplete, it will not even work on the first page.

Here is the relevant part of my code:

        $(document).ready(function(){
            tbl = $('#nutzer').dataTable( {
                "bJQueryUI": true,
                "sScrollX": "100%",
                "bProcessing": true,
                "bServerSide": true,
                "iDisplayLength": 10,
                "sAjaxSource": "xhr.php",
                "sPaginationType": "full_numbers",
                "fnInitComplete": function() {
                    $('#nutzer tbody tr').on("click", function () {
                        aufklappen(this);
                    } );
                }
            } );

            $( "#create-user" ).button().click(function() {
                $( "#dialog-form" ).dialog( "open" );
            });
//            $('#nutzer tbody tr').on("click", function () {
//                aufklappen(this);
//            } );
        });

        function aufklappen(row) {
            if ( tbl.fnIsOpen(row) ) {
                tbl.fnClose(row);
            } else {
                set = tbl.fnSettings().aoOpenRows[0];
                (set != null) ? (tbl.fnClose(set.nParent)) : null;
                $.post("benutzerBearbeiten.php", { 
                    funktion : "benutzerDaten",
                    id : $(row).children( "td:first-child" ).text()
                }, function(data){
                    tbl.fnOpen( row, data);
                    $( "#deaktivieren").button().click(function(e){
                        e.preventDefault();
                        deaktivieren();
                    });
                    $( "#speichern").button().click(function(e){
                        e.preventDefault();
                        speichern();
                    });
                }
            ) };
        }

After loading the page or changing the page pagination of datatables, I can make a manual call

$('#nutzer tbody tr').on('click', function () {
    aufklappen(this);
} );

click tr .

, , datatables-plugin, dom on(), , , .


" ", fnInitComplete

"asStripeClasses": [ "odd nutzer_tr", "even nutzer_tr"]

$("body").delegate(".nutzer_tr", "click", function () {
    aufklappen(this);
});

ready(function()). nutzer_tr , .

+5
1

, :

$('body').on('click', '#nutzer tbody tr', function () {
    aufklappen(this);
});

()

$('body').delegate('#nutzer tbody tr', 'click', function () {
    aufklappen(this);
});
+23

All Articles