jqGrid和jqPivot:如何通过输入标记替换pivot列的值?

时间:2017-12-22 08:25:14

标签: jquery jqgrid free-jqgrid jqpivot

我正在将jqGrid与jqPivot一起使用。

我的数据:

 var data = [{
            Account: "Tom", Contact: "Mary", KindOfCare: 'Birthday', value: 1, notes: 'Birthday'
        }, {
            Account: "Tom", Contact: "Mary", KindOfCare: 'Christmas', value: 0, notes: 'Birthday'
        }, {
            Account: "Tom", Contact: "Mary", KindOfCare: 'New Year', value: 0, notes: 'Birthday'
        }, {
            Account: "Tom", Contact: "Mia", KindOfCare: 'Birthday', value: 0, notes: 'Birthday'
        }, {
            Account: "Tom", Contact: "Mia", KindOfCare: 'Christmas', value: 0, notes: 'Birthday'
        }, {
           Account: "Tom", Contact: "Mia", KindOfCare: 'New Year', value: 0, notes: 'Birthday'
        },
        {
            Account: "Anna", Contact: "David", KindOfCare: 'Birthday', value: 1, notes: 'Birthday'
        }, {
            Account: "Anna", Contact: "David", KindOfCare: 'Christmas', value: 1, notes: 'Birthday'
        }, {
            Account: "Anna", Contact: "David", KindOfCare: 'New Year', value: 0, notes: 'Birthday'
        }, {
            Account: "Selena", Contact: "Bieber", KindOfCare: 'Birthday', value: 0, notes: 'Birthday'
        }, {
            Account: "Selena", Contact: "Bieber", KindOfCare: 'Christmas', value: 1, notes: 'Birthday'
        }, {
           Account: "Selena", Contact: "Bieber", KindOfCare: 'New Year', value: 1, notes: 'Birthday'
        }];

我希望通过输入标记替换pivot列的值,例如:如果value = 1则返回复选框,如果value = 0,则返回复选框

enter image description here

有什么办法吗?

1 个答案:

答案 0 :(得分:1)

如果您在模板中设置空字符串,则此代码将起作用。请查看免费的jqGrid文档什么是tempale以及参数可以接受的可能值

                aggregates: [
                    { member: "KindOfCare",
                    template: "",
                      aggregator: function (options) {
                        //console.log(options);
                        //return options.item.value;
                        if(options.item.value == 1){
                          return '<input class="center" type="checkbox" checked disabled />';
                        }
                        else{
                          return '<input class="center" type="checkbox" disabled />';

                        }
                      } 

                    }
                ]