Tommy1209
Tommy1209

Reputation: 189

jqGrid and jqPivot: How to replace value of pivot column by input tag?

I'm using jqGrid with the jqPivot.

My data:

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

I want replace value of pivot column by input tag, ex: if value = 1 then return checkbox checked, and if value = 0, return checkbox

enter image description here

Any way to do it?

Upvotes: 0

Views: 198

Answers (1)

Tony Tomov
Tony Tomov

Reputation: 3292

This code will work if you set in template empty string. Please look into the free jqGrid docs what is tempale and the possible values the parameter can accept

                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 />';

                        }
                      } 

                    }
                ]

Upvotes: 1

Related Questions