How to get the data-value of selected td?

How to get the data-value of selected td?

Mert1296Mert1296 Posts: 43Questions: 7Answers: 0
edited February 2019 in Free community support

Hi everyone,
I have an issue with the data-value of my td's in my DataTable. When I click the name of the users, I want to open a modal with all informations of the user (in the data-value is the username from the user). But the modal shows only the first user, because the data-value attribute is grouped by name ascending. So I can only see the modal of the first user in the database, when I'm clicking on an other td.

I hope you can help me out :)
Here's a short code example of my drawCallback function:

"drawCallback": function ( settings ) {
                        var api = this.api();
                        var rows = api.rows( {page:'current'} ).nodes();
                        var last=null;

                        api.column(1, {page:'current'} ).data().each( function ( group, i ) {
                            if ( last !== group ) {
                                var groupName = api.row(i).data();
                                $(rows).eq( i ).before(
                                   
                                    '<tr class="group"><td style="font-weight: bold;" data-value="'+groupName[0]+'" data-toggle="modal" data-target="#profileModal" class="tdPerson tdPersonTest" colspan="1">'+group+'</td><td colspan="5"></td></tr>'
                                );
                                last = group;
                            }
                        });
                       
                    }

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @Mert1296 ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • Mert1296Mert1296 Posts: 43Questions: 7Answers: 0

    Hi @colin,
    http://live.datatables.net/cigeyebo/1/edit
    Here is my DataTables initiation :)

    Cheers,
    Mert

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @Mert1296 ,

    There are errors on that page that stops it from running. Also, I can't see where you're creating the modal.

    Cheers,

    Colin

This discussion has been closed.