根据服务代码对数据进行分组,并使用Jquery Datatable显示数据 [英] Group By data on the basis of Service Code and display data using Jquery Datatable

查看:88
本文介绍了根据服务代码对数据进行分组,并使用Jquery Datatable显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是,我想基于来自数据表的Service code按数据分组.我想按datatable中的选定值分组.

What I want is, I want to group by Data based on Service code coming from datatable. I want to group by the selected value from the datatable.

下面是我的数据表屏幕截图

Below is my Datatable screenshot

在上图中,我已经选中了四个复选框.所以我想基于Service Code groupBy这4列数据.

In above picture I have checked four checkboxes. So I want to groupBy those 4 columns data based on the Service Code.

假设前两个已检查行的服务代码为3297392,其他两个已检查行的服务代码为3293490,因此应在下面显示我的数据表

Suppose, the Service code for first two checked rows are 3297392 and for other two checked are 3293490 So it should display my datatable something like below

通过分组,它还会添加SAP ID列和资产计数".

With grouping it also is adding SAP ID column and ASSETS COUNT.

我无法获得确切的逻辑,但是我尝试过的东西如下所示:

I am unable to get the exact logic for that, but something which I tried is like below

function ViewGroupBySummaryData() {

var tableToViewSummary = $('#confirmToFECertify');
tableToViewSummary.empty();

var table = $(dtCertifyEFO).DataTable();
var data = table.rows('.selected').data();   
}

data中,我获得了选定行但没有列的值.

In data I get the values of selected row but without columns.

数据如下所示,在控制台中

The data is like below in console

0:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-APRR-ENB-B002", "INAPAPRRIDETTW6001", "GANESH NAGAR_AT2001", "", "3297392", "MAINTENANCE OF IP COLO ENODEB SITE / IP Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]1:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-APRR-ENB-G001", "INAPAPRRYRNLNB6001", "VENUGOPAL NAGAR", "", "3297392", "MAINTENANCE OF IP COLO ENODEB SITE / IP Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]2:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-BRYS-ENB-6000", "INAPBRYSBRYSTW6001", "Bukkarayasamudram", "", "3293490", "MAINTENANCE OF RCOM COLO ENODEB SITE / R-Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]3:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-BRYS-ENB-6001", "INAPBRYSXXXXTW6003", "CHENNAMPALLE", "", "3293490", "MAINTENANCE OF RCOM COLO ENODEB SITE / R-Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]

0:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-APRR-ENB-B002", "INAPAPRRIDETTW6001", "GANESH NAGAR_AT2001", "", "3297392", "MAINTENANCE OF IP COLO ENODEB SITE / IP Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]1:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-APRR-ENB-G001", "INAPAPRRYRNLNB6001", "VENUGOPAL NAGAR", "", "3297392", "MAINTENANCE OF IP COLO ENODEB SITE / IP Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]2:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-BRYS-ENB-6000", "INAPBRYSBRYSTW6001", "Bukkarayasamudram", "", "3293490", "MAINTENANCE OF RCOM COLO ENODEB SITE / R-Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]3:(14)[
"", "<a class=" actionIcon" id="discripancy"><i class="fa fa-flag"></i></a>", "I-AP-BRYS-ENB-6001", "INAPBRYSXXXXTW6003", "CHENNAMPALLE", "", "3293490", "MAINTENANCE OF RCOM COLO ENODEB SITE / R-Colo", "ACTIVE", "12/11/2014", "", "Mahindra &amp; Mahindra Limited - 168888", "", "" ]

请帮助我使用jquery数据表构建逻辑.

Please help me to build the logic using jquery datatable.

下面是我的HTML

<table id="confirmToFECertify" class="myTable table table-striped table-bordered nowrap" cellspacing="0"></table>

推荐答案

这里是方法:

显示一个新的数据表,并用代码和所选元素的总和填充其行.由于代码段并未真正模拟click事件,因此未对代码进行测试. r[5](分别为r[6])对应于SAP ID和assets count的行.我在您提供的console.log信息中看不到这些字段的值.您可以更改56以满足表字段的位置.

Display a new datatable and populate its rows with the code and the sum of selected elements. The code is not tested since the snippet does not really simulate the click event. r[5] (respectively r[6]) corresponds to the row of SAP ID and assets count. I can't really see the values of those fields in the console.log information you provided. You can change 5 and 6 to meet your table field position.

function ViewGroupBySummaryData() {

    var tableToViewSummary = $('#confirmToFECertify');
    tableToViewSummary.empty();

    console.log($(dtCertifyEFO));

    var table = $(dtCertifyEFO).DataTable();
    var data = table.rows('.selected').data().toArray();

    var newData = {};
    data.forEach(r => {
        var code = newData[r[6]]
        if (code) {
            // if the code is already present sum the value of each row
            newData[code] = [newData[code][0] + parsefloat(r[5]), newData[code][1] + parsefloat(r[7])]
        } else {
            // add new row corresponding to the code
            newData[code] = [parsefloat(r[5]), parsefloat(r[7])]
        }
    })
    // create new DataTable
    var t = $('#example').DataTable();

    // add rows to the new datatable
    Object.keys(newData).forEach(function(k) {
        var values = [];
        values.push(k);
        for ( var i = 0; i < newData(k).length; i++) {
          values.push(i)
        }
        t.row.add(values)
    })

    // display the new datatable

}

这篇关于根据服务代码对数据进行分组,并使用Jquery Datatable显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆