Datatable accordeon

Datatable accordeon

jojo____jojo____ Posts: 9Questions: 5Answers: 0

Hi everybody,

I'm trying to make an accordeon inside a datatable but I have no idea how this can be done. I have a datatable listing users. By click on a row (one user), I want to add a row (without columns) and show in there more information about the user. By clicking on another row, the first additionnal disappear and a new one appears under the new selected row with the detailed information about the selected user.

Is this actually possible ?

Thanks !

Answers

  • jojo____jojo____ Posts: 9Questions: 5Answers: 0

    I found something that would be perfect:

    function format(d) {
    // d is the original data object for the row
    return '

    ' + '' + '' + '' + '' + '' + '' + '' + '' + '
    Email:' + d.message + '
    Extension number:' + d.attachmentPath + '

    ';
    }
    $(document).ready(
    function() {
    var table = $('#listOfEmails').DataTable({
    "bPaginate" : false,
    "oLanguage" : {
    "sInfo" : ""
    },
    "sScrollY" : "400px",

                    });
    
                    // Add event listener for opening and closing details
                    $('#listOfEmails tbody').on('click', 'tr',
                            function() {
    
                                var row = table.row($(this));
                                if (row.child.isShown()) {
                                    // This row is already open - close it
                                    row.child.hide();
                                    tr.removeClass('shown');
                                } else {
                                    // Open this row
    
                                    row.child(format(row.data())).show();
                                    tr.addClass('shown');
                                }
                            });
    

    The problem is that this need an ajax entry. I am working with jee and my datatable is filled with an array that I get from my controller. I made a foreach to go through the array and add the rows. Is it still possible without ajax ? :s

  • ashiersashiers Posts: 101Questions: 8Answers: 7

    If you are just working with DataTables by itself, then you'll probably will want to use JED on the server side to accomplish what you want. I see you're on the Java platform, so getting acquainted with JED is your best option: http://jed-datatables.ca/jed/

This discussion has been closed.