当前位置: 首页 > 知识库问答 >
问题:

在Datatables服务器端处理中添加音频控件和按钮

殷承恩
2023-03-14

我将Datatables与Codeigniter-PHP一起使用。

现在在一个表中,我有非常大的数据,所以我使用Datatables服务器端处理来显示我的数据。

我有一个可以播放的音频文件和一个下载文件的按钮。

更早的时候,当我不使用服务器端处理我用来显示它像这样:

<table id="dtMaterialDesignExample" class="table table-striped table-bordered example hoverable"  style="width:100%">
    <thead>
        <tr>
            <th><i class="fas fa-user"></i> Caller </th>
            <th><i class="fas fa-calendar-week"></i> Date</th>
            <th><i class="fas fa-clock"></i> Duration</th>

            <th><i class="fas fa-sort-numeric-down"></i> Recipient Number</th>
            <th><i class="fas fa-play"></i> Recording</th>
            <th><i class="fas fa-download"></i> Download</th>
        </tr>
    </thead>
    <tbody>
       <?php if(count($reports)): foreach($reports as $report): ?>   
        <tr >
            <td><?php echo $report->src; ?></td>
            <td><?php echo $report->calldate; ?></td>
            <td><?php echo $report->duration; ?> Seconds</td>

            <td><?php echo $report->dst; ?></td>
            <td> 
              <audio controls controlsList="nodownload">
                  <source src="<?php echo ccs_recording_path.$report->filename.'-all.mp3'; ?>" type="audio/ogg" data-recordings = "<?php echo $report->filename.'-all.mp3'; ?>">
              </audio>
            </td>
            <td style="text-align: center;"><a href="<?php echo ccs_recording_path.$report->filename.'-all.mp3'; ?>"><i class="fas fa-2x fa-file-download"></i></a> </td>

        </tr>

        <?php endforeach; ?>
          <?php else: ?>
          <tr>
              <td colspan="10">No Records Available</td>
          </tr>
          <?php endif; ?> 
    </tbody>

</table>

现在我已经添加了服务器端我的代码是:

超文本标记语言

<table id="dtMaterialDesignExample" class="table table-striped table-bordered example hoverable"  style="width:100%">
<thead>
    <tr>
        <th><i class="fas fa-user"></i> Caller </th>
        <th><i class="fas fa-calendar-week"></i> Date</th>
        <th><i class="fas fa-clock"></i> Duration</th>

        <th><i class="fas fa-sort-numeric-down"></i> Recipient Number</th>
        <th><i class="fas fa-play"></i> Recording</th>
        <th><i class="fas fa-download"></i> Download</th>
    </tr>
</thead>

</table>

PHP

public function response()
{
    $from_date = "2019-01-01 00:00:00";
    $to_date   = "2019-01-23 00:00:00"; 

    $response = $this->Report_m->get_agent_cdr($from_date,$to_date);

    $response = ["sEcho" => 1,
        "iTotalRecords" => count($response),
        "iTotalDisplayRecords" => count($response),
        "aaData" => $response ];


    $response = json_encode($response);

    echo $response;

}

JAVASCRIPT

$(document).ready(function () {
var table = $('#dtMaterialDesignExample').DataTable({
"lengthMenu": [[5,10, 25, 50, -1], [5,10, 25, 50, "All"]],
"sAjaxSource": "<?php echo site_url('CDR/response'); ?>",
"bProcessing": true,
"aoColumns": [
        { mData: 'src' } ,
        { mData: 'calldate' },
        { mData: 'duration'},
        { mData: 'dst'},
        { mData: '<audio controls controlsList="nodownload"><source src="<?php echo ccs_recording_path.$report->filename.'-all.mp3'; ?>" type="audio/ogg" data-recordings = "<?php echo $report->filename.'-all.mp3'; ?>"></audio>'},
        { mData: '<a href="<?php echo ccs_recording_path.$report->filename.'-all.mp3'; ?>"><i class="fas fa-2x fa-file-download"></i></a>'},
      ],
  dom: '<"float-left"B><"float-right"f>rt<"row"<"col-sm-4"l><"col-sm-4"i><"col-sm-4"p>>',
  fixedHeader: true,
    buttons: [
        {
            extend: 'csvHtml5',
            title: 'bizRTC CDR <?php date('d-m-Y'); ?>',
             customize: function (csv) {
                 return "Enjoy the file"+csv;
              },
               className: 'btn btn-outline-primary waves-effect space',
        },
        {
        extend: 'pdfHtml5',
        title: 'CDR <?php echo date('d-m-Y'); ?>',
        customize: function ( doc ) {
                        doc.content.splice( 0, 0, {
                            text: "bizRTC CDR"
                        } );
        },
        className: 'btn btn-outline-primary waves-effect space',
        },
        {
            extend: 'excelHtml5',

            title: 'bizRTC CDR <?php date('d-m-Y'); ?>',
            message: "Call Records",
            className: 'btn btn-outline-primary waves-effect space',


        },
    ],

  responsive: {
        details: {
            display: $.fn.dataTable.Responsive.display.modal( {
                header: function ( row ) {
                    var data = row.data();
                    return 'Details for '+data[0]+' '+data[1];
                }
            } ),
            renderer: $.fn.dataTable.Responsive.renderer.tableAll( {
                tableClass: 'table'
            } )
        }
    },
    "drawCallback": function () {
        $('.dataTables_paginate > .pagination').addClass('pagination pagination-circle pg-blue mb-0');
    }
});

对于最后两栏,我有音频播放器和按钮,我如何在数据表上显示它们?

共有1个答案

邓建柏
2023-03-14

您可以使用Datatable中的columnDefs来呈现Datatable中的自定义列值,如下所示:,

var table = $('#myTable').DataTable( {
    columnDefs: [
        { 
         targets: [5],//<- target column index 
         visible: true,
         render: function ( data, type, row, meta ){
            return `<audio controls controlsList="nodownload">
              <source src="<?php echo ccs_recording_path.$report->filename.'-all.mp3'; ?>" type="audio/ogg" data-recordings = "<?php echo $report->filename.'-all.mp3'; ?>">
          </audio>`
          }
        },

    ]
} );

这只是你理解的代码片段,你必须根据你的代码做一些调整。你可以在这里读到更多,

https://datatables.net/reference/option/columns.render

 类似资料:
  • 问题内容: 问题: 使用ASP.NET WebForms的jQuery DataTables服务器端处理。 解: 达林·迪米特洛夫(Darin Dimitrov)使用一个分页和排序但不进行任何搜索的示例回答了这个问题。这是我对他的作品进行的“基本”修改,以使他的示例可以进行搜索: 问题答案: 我写了一个简单的例子来说明这个想法。 首先,编写用于在服务器端处理数据的通用处理程序(但这可以是网页,We

  • 我正在尝试使用jQuery DataTables AJAX服务器端脚本。。。 我需要将wp_usermeta表与wp_users表连接起来。。。 如何使用示例服务器端处理脚本加入wp_usermeta表?脚本可以在https://datatables.net/examples/server_side/simple.html找到 相关代码是

  • 我在我的项目中使用微服务架构。对于服务间通信,我使用消息队列NATS。我写了一个网关,处理所有超文本传输协议请求,并将其放入队列。所有终端服务都订阅到这个队列。 在endpoint服务中,我使用基于Netty IO的Xitrum。当我从队列中得到请求时,我将其反序列化为FullHttpRequest。但我不知道如何将它发送到我的netty服务器,它可以根据业务逻辑处理它(例如,不使用可以将它发送到

  • 我使用org.eclipse.jetty.server.handler.请求日志处理程序 但此处理程序日志仅: 0:0:0:0:0:0:0:1--[04/θών/2014:08:16:27 0000]“GET/CardTransfer-0.1.0-SNAPSHOT/transf HTTP/1.1“200 22”-“Mozilla/5.0(Windows NT 6.1;WOW64;rv:29.0)G

  • 我为此挣扎了好几天。我正在尝试将Sergio Llana的服务器端解决方案应用到我现有的项目中。 Sergio的数据表服务器端处理 这是我的实现: 我的数据表服务器端处理 不同的是,我的解决方案从MySQL数据库抓取数据,而不是本地文件。我认为我很接近使它工作,从数据库的数据显示在表中正确。当我关闭服务器端选项,排序和搜索工作正常,但当我打开它,每次我点击列,搜索或其他任何东西,我得到的只是"处理

  • 本文向大家介绍datatables 带查询条件java服务端分页处理实例,包括了datatables 带查询条件java服务端分页处理实例的使用技巧和注意事项,需要的朋友参考一下 使用datatables自带后台查询 前台代码: Java代码如下,使用spring的 @ResponseBody将结果转换成json格式返回给前台 DatatablesViewPage的声明如下: 在后台传输数据也可以

  • 我是Java新手,希望接受包含股市详细信息的字符串。如果现有字符串包含脚本的购买订单,请按给定价格查找卖家。如果没有匹配项可用,则将新订单添加到现有采购订单队列。 这些需要尽可能快地完成,或者最好并行完成,以便给定的应用程序可以在最短的时间内处理尽可能多的订单。

  • 有人可以请给我一个Android辅助功能服务实时音频处理的示例代码。我需要处理呼叫音频。但不知道如何实现这一点。请分享您对此的看法 请查看以下清单: 请在下面查找可访问性xml: PFB服务: