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

192 views Asked by At

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?

1

There are 1 answers

5
Tony Tomov On BEST ANSWER

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

                        }
                      } 

                    }
                ]