if ( $this -> getRequest ()-> isPost () ){ $where = []; $search = isset ( $_POST [ 'report' ]) ? $_POST [ 'report' ] : []; //$where = [ 'uid'=>$uid ]; //根据日期查询 if ( isset ( $search [ 'start_time' ]) && $search [ 'start_time' ]){ $where [] = [ 'report_time' , '=' , $search [ 'start_time' ]]; /**排序处理*/ $usort = 'report_time' ; $uorder = 'DESC' ; //给默认值 if ( isset ( $_POST [ 'sort' ]) ) $usort = $_POST [ 'sort' ]; if ( isset ( $_POST [ 'order' ]) ) $uorder = $_POST [ 'order' ]; $mReport = new ReportModel (); $rows = $mReport -> getList ( $where , 'id,report_time,upload_num,recomme_num' , ( int ) $_POST [ 'page' ], ( int ) $_POST [ 'rows' ], [ $usort , $uorder ] ); if ( $rows ){ $upload_num = $recomme_num = 0 ; foreach ( $rows as $k => $v ){ $upload_num += $v [ 'upload_num' ]; $recomme_num += $v [ 'recomme_num' ]; $total = $mReport -> count ( $where ); $footer = [ 'report_time' => '<b>合计<b>' , 'upload_num' => '<b>' . $upload_num . '</b>' , 'recomme_num' => '<b>' . $recomme_num . '</b>' ]; $data [ 'rows' ] = $rows ; $data [ 'total' ] = $total ; $data [ 'footer' ] = [ $footer ]; die ( json_encode ( $data ) ); (2)、返回的数据格式:添加 footer行

result = ['rows' => [    0 => ['upload_num' => 0,'recomme_num' => 0,'report_time' => '2018-06-20',],
                         1 => ['upload_num' => 1,'recomme_num' => 0,'report_time' => '2018-06-19',],
           'total' => 80,
           'footer' => [ [ 'upload_num' => 6,'recomme_num' => 0,'report_time' => '总计',] ]    
            //想显示什么就在这设置什么,''为不显示
(3)、datagrid设置参数
showFooter: true,
2、在rows中添加一行
(1)、后台返回数据不变,前台js组装一行数据
1)、在datagrid表中添加onLoadSuccess事件

onLoadSuccess:function(data){
    $('#easyuiTable_id').datagrid('appendRow', {
        report_time: '<b>合计</b>',
        upload_num: getTotal("upload_num"),
        recomme_num:getTotal("recomme_num"),
2)、getTotal方法计算总数

function getTotal(colName) {
    var rows = $('#easyuiTable_id').datagrid('getRows');
    var total = 0;
    for (var i = 0; i < rows.length; i++) {
        total += parseFloat(rows[i][colName]);
    return '<b>'+total+'</b>';
(2)、前台不变,后台添加一条合计数据
if($rows){
    $upload_num = $recomme_num = 0;
    foreach ($rows as $k => $v){
        $upload_num += $v['upload_num'];
        $recomme_num += $v['recomme_num'];
    $temp = ['report_time'=>"<b>合计</b>", 'upload_num'=>'<b>'.$upload_num.'</b>', 
             'recomme_num'=>'<b>'.$recomme_num.'</b>' ];
    //$rows[] = $temp;            //(1)、直接追加在数组后面
    //array_push($rows, $temp);    //(2)、追加到数组的最后一位
    array_unshift($rows, $temp);    //追加到数组的第一位

分类:
后端
标签: