【问题标题】:How can I create a clickable link with Yajra data-tables server side如何使用 Yajra 数据表服务器端创建可点击的链接
【发布时间】:2020-01-10 03:11:47
【问题描述】:

我获取所有数据的控制器。

return Datatables::of($usersData)->make(true); 

在观点上:

<table id="AllData" class="table table-striped display" cellspacing="0" width="100%" >
            <thead>
            <tr>
                <th>Subject</th>
                <th>Business</th>
                <th>Device</th>
            </tr>
            </thead>
            </table> 

然后是 JavaScript

<script type="text/javascript">
        $(document).ready(function() {
             $('#AllData').DataTable({
                dom: 'Bfrtip',
                aLengthMenu: [[5, 10, 25], [5, 10, 25]],
                iDisplayLength: 10,
                processing: true,
                serverSide: true,
                responsive: true,
                autoWidth:false,
                "ajax": "{{ url('get-all-review-data') }}",
                "columns":[
                    { "data": "subject"},
                    { "data": "businessName" },
                    { "data": "device_name" }
                ],
                buttons: ['csv', 'excel', 'pdf', 'colvis']
             });
        });
    </script> 

这很好用。我可以查看数据。

但是,我希望将第一个 td 作为链接作为&lt;td&gt;&lt;a href="/review/show/{!! &gt;reviewSlug !!}" target="_blank"&gt;{!! subject !!}&lt;/a&gt;&lt;/td&gt;

我怎样才能做到这一点?

【问题讨论】:

    标签: laravel laravel-5 yajra-datatable


    【解决方案1】:

    您可以使用列数据渲染

    "columns":[
         { "data": "subject", "render": function ( data, type, row, meta ) {
                return  `<a href="/review/show/${yourSlug}" target="_blank">${data}</a>`;
            };
         },
         { "data": "businessName" },
         { "data": "device_name" }
    ],
    

    【讨论】:

    • yourSlug 是 reviewSlug,数据是 subject 我如何传递它们以显示在链接上?
    • subject 已经与名称数据一起传递,因为您在渲染函数中,您可以检查行的值
    【解决方案2】:
    { data: 'id', name: 'id', render:function(data, type, row){
        return "<a href='/users/"+ row.id +"'>" + row.id + "</a>"
    }},
    

    【讨论】:

      猜你喜欢
      • 2019-07-15
      • 1970-01-01
      • 2016-09-17
      • 2020-07-17
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      相关资源
      最近更新 更多