数据表-带有响应的扩展文本列

时间:2018-08-31 13:45:55

标签: datatable datatables

https://legacy.datatables.net/ref#

我知道这些是旧数据表,但是我想准确地模仿“目的”列的设置方式。截断文字,然后在展开详细信息后再加上完整文字。

我该怎么做?

<script src="https://code.jquery.com/jquery-3.3.1.js"></script>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/datatables.min.css"/>

<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/datatables.min.js"></script>


<script>

    $(document).ready(function() {
    $('#example').DataTable( {

  columnDefs: [ {

        targets: 1,

        render: function ( data, type, row ) {

    return data.length > 15 ?

        data.substr( 0, 15 ) +'…' :

        data;
}

}],

responsive: true
    } );
} );

</script>



<table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Description</th>

                <th class="none">Branch</th>

            </tr>
        </thead>


        <tbody>
            <tr>
                <td>Test 1</td>
                <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</td>

                <td>ABC</td>

            </tr>          
        </tbody>    
    </table>

0 个答案:

没有答案