【问题标题】:jqGrid and jqPivot: How to replace value of pivot column by input tag?jqGrid 和 jqPivot:如何用输入标签替换数据透视列的值?
【发布时间】:2017-12-22 08:25:14
【问题描述】:

我将 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'
        }];

我想用输入标签替换数据透视列的值,例如:如果值 = 1,则返回复选框选中,如果值 = 0,则返回复选框

有什么办法吗?

【问题讨论】:

  • 我在这里:plnkr.co/edit/WfRtXnUk9KqarOfdp63L?p=preview。我尝试返回 '' 但不工作,结果返回 NaN
  • 您的数据透视设置是从另一个代码复制/粘贴,与您的实际数据没有任何关系。为了帮助您需要根据您的数据进行设置
  • @TonyTomov,我更新了我的 plunk,请再试一次
  • @TonyTomov,你能不能用复选框 checked 替换 1,用复选框 not checked 替换 0
  • 由于您使用 free-jqGrid 我无法告诉您传递给函数的参数是什么 - 在 Guriddo jqGrid 中这很容易,您可以阅读docs 做什么,但在您可能不想将数据用作数字以便按照您的建议设置输入

标签: jquery jqgrid free-jqgrid jqpivot


【解决方案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 />';

                        }
                      } 

                    }
                ]

【讨论】:

  • 我删除了 template 但没有将其设为空字符串,所以它错了。感谢您的解决方案。太好了!
  • 谢谢。很高兴能提供帮助。
  • 还有一个小问题:有没有办法在网格末尾添加列Notes,使其看起来像上图?
  • 对不起,在这种情况下我无能为力。我只知道 Guriddo jqGrid 的答案
  • 我明白了。感谢您的帮助!
猜你喜欢
  • 2021-10-13
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 2019-12-03
相关资源
最近更新 更多