Add "data-title" to every

Add "data-title" to every

ierpeierpe Posts: 6Questions: 1Answers: 0

Hi,

In order to achieve something like this : http://elvery.net/demo/responsive-tables/ , I would to add a "data-title=[column-name]" to every <td> element.

Any idea on how to achieve this?

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    edited January 2015

    You would need to use columns.createdCell to add the attribute.

    Another option, although not exactly the same, might be to use Responsive.

    Allan

  • ierpeierpe Posts: 6Questions: 1Answers: 0

    Thanks for your answer, at the end I did it this way :

    //add data-title to every <td>
    $('table#my_table thead tr th').each(function(index,element){
        index += 1;
        $('tr td:nth-child('+index+')').attr('data-title',$(this).attr('data-title'));
    });
    

    I added this code to the "initComplete" and "drawCallback" events (I'm using ajax)

    I will also try the columns.createdCell thanks for that!

    For info the "responsive" link you posted isn't working.

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Doh - link fixed!

This discussion has been closed.