【问题标题】:Show only unique data for a column - jQuery data tables仅显示列的唯一数据 - jQuery 数据表
【发布时间】:2015-04-20 07:58:11
【问题描述】:

我正在使用 Data Tables 并且只想显示列 day 的唯一数据。

这是我的桌子:

#   Day         Count
---------------------
1   Friday      2
2   Friday      2
3   Saturday    4
.   .       .
.   .       .

JS:

var myTable = $('.table').DataTable({
        "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
        "oLanguage": {
            "oPaginate": {
                "sPrevious": "←", // This is the link to the previous page
                "sNext": "→", // This is the link to the next page
            }
        }
    });

如何过滤数据以仅显示表中唯一的日期数据?

我知道那里有 unique() 函数,但这仅用于从表中选择唯一列数据,而不是我需要(通过重建可能)表显示具有唯一数据的列。

感谢您的帮助。

【问题讨论】:

  • 你是如何获取数据并显示在表格上的?
  • 来自 api,但不需要从 api 发送唯一的。 @sgt

标签: javascript jquery datatables unique jquery-datatables


【解决方案1】:

您可以通过创建 custom row filter 来实现:

var day,
    days = [];

$.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
        //return true if iDataIndex already is processed
        if (days[iDataIndex]) return true;
        //process day, return true and insert into days if not already known
        day = aData[1];        
        if (days.indexOf(day)<0) {
           days[iDataIndex]=day;
           return true;
        } else {
           return false;
        }     
    }     
);

演示 -> http://jsfiddle.net/4abqjxcu/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-11
    • 2018-04-19
    • 2021-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2015-07-15
    相关资源
    最近更新 更多