数据表行开始和结束分组

时间:2017-09-19 05:18:03

标签: javascript datatable

我尝试了下面的功能,如何为分组页眉和页脚添加css样式?对于页脚,也许这是可能的,但我怎么能为标题做呢?

$(document).ready(function() {
    $('#example').DataTable( {
        order: [[2, 'asc']],
        rowGroup: {             
            endRender: function ( rows, group ) {
                var salaryAvg = rows
                    .data()
                    .pluck(5)
                    .reduce( function (a, b) {
                        return a + b.replace(/[^\d]/g, '')*1;
                    }, 0) / rows.count();
                salaryAvg = $.fn.dataTable.render.number(',', '.', 0, '$').display( salaryAvg );

                var ageAvg = rows
                    .data()
                    .pluck(3)
                    .reduce( function (a, b) {
                        return a + b*1;
                    }, 0) / rows.count();

                return $('<tr/>')
                    .append( '<td colspan="3">Averages for '+group+'</td>' )
                    .append( '<td>'+ageAvg.toFixed(0)+'</td>' )
                    .append( '<td/>' )
                    .append( '<td>'+salaryAvg+'</td>' );
            },
            dataSrc: 2
        }
    } );
});

2 个答案:

答案 0 :(得分:1)

只是css

tr.group{
    background-color: #690505 !important;
    color: white !important;
}

tr.group:hover {
    background-color: #871818 !important;
    color: white !important;
}

答案 1 :(得分:0)

package com.examples

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext

object ReCalculationModified {
  def main(args: Array[String]) {
    val conf = new SparkConf().setMaster("local[1]").setAppName("RecalculationModified")
    val sc = new SparkContext(conf)

    val vertex = Array(
  (0, Array(0, 0, 0, 0)),
  (1, Array(0, 0, 0, 0)),
  (2, Array(0, 0, 0, 0)),
  (3, Array(0, 0, 0, 0)))

    val vertexRDD = sc.makeRDD(vertex).map(x => x).cache()
    val newVert1 = vertexRDD.map {
      case (vid, array) =>
        array(vid) += 1
        (vid, array)
    }
    println("--------------newVertex1-------------")
    newVert1.foreach(x => println(x._1 + ":" + x._2.toBuffer))
    println("--------------VertexRDD-------------")
    vertexRDD.foreach(x => println(x._1 + ":" + x._2.toBuffer))

    // Output of both vertexRDD and newVert1 is
    //      0:ArrayBuffer(1, 0, 0, 0)
    //      1:ArrayBuffer(0, 1, 0, 0)
    //      2:ArrayBuffer(0, 0, 1, 0)
    //      3:ArrayBuffer(0, 0, 0, 1)   

    val newVert2 = newVert1.map {
      case (vid, array) =>
        array(vid) += 1
        (vid, array)
    }
    println("--------------newVertex2-------------")
    newVert2.foreach(x => println(x._1 + ":" + x._2.toBuffer))
    println("--------------VertexRDD-------------")
    vertexRDD.foreach(x => println(x._1 + ":" + x._2.toBuffer))

    // Output of both vertexRDD and newVert2 is
    //      0:ArrayBuffer(3, 0, 0, 0)
    //      1:ArrayBuffer(0, 3, 0, 0)
    //      2:ArrayBuffer(0, 0, 3, 0)
    //      3:ArrayBuffer(0, 0, 0, 3)

     val newVert3 = newVert2.map {
      case (vid, array) =>
        array(vid) += 1
        (vid, array)
    }
    println("--------------newVertex3-------------")
    newVert3.foreach(x => println(x._1 + ":" + x._2.toBuffer))
    println("--------------VertexRDD-------------")
    vertexRDD.foreach(x => println(x._1 + ":" + x._2.toBuffer))

    // Output of both vertexRDD and newVert3 is
    //      0:ArrayBuffer(6, 0, 0, 0)
    //      1:ArrayBuffer(0, 6, 0, 0)
    //      2:ArrayBuffer(0, 0, 6, 0)
    //      3:ArrayBuffer(0, 0, 0, 6)

         val newVert4 = newVert3.map {
      case (vid, array) =>
        array(vid) += 1
        (vid, array)
    }
    println("--------------newVertex4-------------")
    newVert4.foreach(x => println(x._1 + ":" + x._2.toBuffer))
    println("--------------VertexRDD-------------")
    vertexRDD.foreach(x => println(x._1 + ":" + x._2.toBuffer))

    // Output of both vertexRDD and newVert4 is
    //      0:ArrayBuffer(10, 0, 0, 0)
    //      1:ArrayBuffer(0, 10, 0, 0)
    //      2:ArrayBuffer(0, 0, 10, 0)
    //      3:ArrayBuffer(0, 0, 0, 10)

    val newVert5 = newVert4.map {
      case (vid, array) =>
        array(vid) += 1
        (vid, array)
    }
    println("--------------newVertex5-------------")
    newVert5.foreach(x => println(x._1 + ":" + x._2.toBuffer))
    println("--------------VertexRDD-------------")
    vertexRDD.foreach(x => println(x._1 + ":" + x._2.toBuffer))

    // Output of both vertexRDD and newVert5 is
    //      0:ArrayBuffer(15, 0, 0, 0)
    //      1:ArrayBuffer(0, 15, 0, 0)
    //      2:ArrayBuffer(0, 0, 15, 0)
    //      3:ArrayBuffer(0, 0, 0, 15)  

  }
}