Datatables Complex标头+ sum api不起作用

时间:2016-08-24 09:25:53

标签: javascript jquery datatables

我在组合数据表的复杂标题+ sum()方面遇到了麻烦。

JS

$('#mainTable').DataTable({
    "initComplete": function () {
        this.api().columns('.sum').every(function () {
            var column = this;

            var sum = column
               .data()
               .reduce(function (a, b) { 
                   a = parseInt(a, 10);
                   if(isNaN(a)){ a = 0; }

                   b = parseInt(b, 10);
                   if(isNaN(b)){ b = 0; }

                   return a + b;
               });

            $(column.footer()).html(sum);
        });
    }
});

选中此笔以获取完整代码:

http://codepen.io/JefMari/pen/mEYXya

1 个答案:

答案 0 :(得分:1)

问题不在于标题,而是数字周围的强标记。例如,使用正则表达式去除计算的数字。

// your arg input object
var inputType = new GraphQLInputObjectType({
    name: 'paymentInput',
    fields: {
        user: {
            type: new GraphQLNonNull(GraphQLString)
        },
        order: {
            type: GraphQLString
        },
        ...another fields
    }
});

var Query = new graphQL.GraphQLObjectType({
    name: 'Query',
    fields: {
        payment: {
            type: graphQL.GraphQLString,
            args: {
                data: { type: new GraphQLNonNull(inputType) }
            },
            resolve: function (_, args) {
                // There will be more data here,
                // but ultimately I want to return a string
                return 'success!';
            }
        }
    }
});