Data Tables, select current row with highlight

Data Tables, select current row with highlight

OdynOdyn Posts: 8Questions: 2Answers: 0

Hello team

I have simple table create using Data Tables

I have a lot of records populate dynamically from JSON object

<table id="jobs" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <td>ID</td>
            <td>InvoiceNumber</td>
            <td>PagesCount</td>
            <td>Status</td>
        </tr>
    </thead>
</table>

I would like to allow current row selection with highlight

Is there any ready to use function for that?

Thanks
Adam

Replies

  • OdynOdyn Posts: 8Questions: 2Answers: 0

    Already was able to select record and remove it from frontend using DELETE button

    $(document).ready(function() {
        var table = $('#jobs').DataTable();
    
        $('#jobs tbody').on( 'click', 'tr', function () {
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            else {
                table.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        } );
    
        $('#delete-button').click( function () {
            table.row('.selected').remove().draw( false );
        } );
    } );
    

    But how to pass (capture record ID) later

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    This example shows how to get the row data of the clicked row.

    Kevin

  • OdynOdyn Posts: 8Questions: 2Answers: 0

    Thank You

    I also fed the row ID during table initialization from ID from JSON.

This discussion has been closed.