Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery-JTable: add on click event for row?

I have to following code to show my user table, this is achieved by JTable.

<script type="text/javascript">
    $(document).ready(function() {              
        $('#userTableContainer').jtable({
            title: 'Users',
            selecting: false,
            paging: true,
            pageSize: 15,
            sorting: true,
            addRecordButton: false,
            saveUserPreferences: false,
            create: false,
            edit: false,
            actions: {
                listAction: 'user/getUsers.htm',
            },
            fields: {
                username: {
                    title: 'username'
                },
                firstname: {
                    title: 'firstname'
                },
                lastname: {
                    title: 'lastname'
                },
                company: {
                    title: 'company'
                }
             }
        });
        $('#userTableContainer').jtable('load');              
    });    

</script>

<div id="content">
    <h1>Users</h1>      

    <br />
    <div id="userTableContainer">

    </div>
</div>

Is it possible to add a custom action event for every row? So that i could submit a request like "user/showUser.htm" to my controller.

like image 360
James Carter Avatar asked Apr 08 '13 14:04

James Carter


1 Answers

This should get you on your way:

$('#userTableContainer').jtable({
    ....
    recordsLoaded: function(event, data) {
        $('.jtable-data-row').click(function() {
            var row_id = $(this).attr('data-record-key');
            alert('clicked row with id '+row_id);
        });
    }
});
like image 132
Jules Colle Avatar answered Oct 06 '22 23:10

Jules Colle