jQuery DataTables: Custom control does not work on second page (Solution 2)

Example for article at https://www.gyrocode.com/articles/jquery-datatables-custom-control-does-not-work-on-second-page/

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/raty/2.7.0/jquery.raty.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/raty/2.7.0/jquery.raty.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/r/dt/dt-1.10.9,r-1.0.7/datatables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.css">
<script src="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.js"></script>
<h3><a target="_blank" href="https://www.gyrocode.com/articles/jquery-datatables-custom-control-does-not-work-on-second-page/">jQuery DataTables: Custom control does not work on second page</a> </h3>

<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Rating</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Rating</th>
            <th>Salary</th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td data-order="4"><span class="rating" data-score="4"></span></td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td data-order="3"><span class="rating" data-score="3"></span></td>
            <td>$170,750</td>
        </tr>
        <tr>
            <td>Ashton Cox</td>
            <td>Junior Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td data-order="1"><span class="rating" data-score="1"></span></td>
            <td>$86,000</td>
        </tr>
        <tr>
       ...

JavaScript

$(document).ready(function() {
    var table = $('#example').DataTable({
        columnDefs: [
            { targets: 4, width: '100px' }
        ],
        initComplete: function(settings){
            var api = new $.fn.dataTable.Api( settings );
            
            // Initialize custom control
            $('span.rating', api.rows().nodes()).raty({
                half: true,
                starHalf: 'https://cdnjs.cloudflare.com/ajax/libs/raty/2.7.0/images/star-half.png',
                starOff: 'https://cdnjs.cloudflare.com/ajax/libs/raty/2.7.0/images/star-off.png',
                starOn: 'https://cdnjs.cloudflare.com/ajax/libs/raty/2.7.0/images/star-on.png',
                score: function(){
                    return $(this).data('score');
                },
                click: function(score){
                    $(this).data('score', score);
                }
            });
        }
    });
});