Knockoutjs templates and data binding can be used in grid cells by defining the template property of columns in colModel.

pqGrid compiles the templates and adds binding context to each of them with following properties:

Koockoutjs grid
 
Company
Revenues
Profits
 
 
 
 
 
1Exxon Mobil33993836130
2Wal-Mart Stores31565411231
3Royal Dutch Shell30673125311
4BP26760022341
5General Motors192604-10567
6Chevron18948114099
7DaimlerChrysler186106.33536.3
8Toyota Motor18580512119.6
9Ford Motor1772102024
10ConocoPhillips16668313529
11General Electric15715316353
12Total152360.715250
13ING Group138235.38958.9
14Citigroup13104524589
15AXA129839.25186.5
16Allianz1214065442.4
17Volkswagen118376.61391.7
18Fortis112351.44896.3
19Crédit Agricole110764.67434.3
20American Intl. Group10890510477
Loading...


57
 
1
2
$(function () {
3
    var data = [
4
        { rank: 1, company: 'Exxon Mobil', revenues: 339938.0, profits: 36130.0 },
5
        { rank: 2, company: 'Wal-Mart Stores', revenues: 315654.0, profits: 11231.0 },
6
        { rank: 3, company: 'Royal Dutch Shell', revenues: 306731.0, profits: 25311.0 },
7
        { rank: 4, company: 'BP', revenues: 267600.0, profits: 22341.0 },
8
        { rank: 5, company: 'General Motors', revenues: 192604.0, profits: -10567.0 },
9
        { rank: 6, company: 'Chevron', revenues: 189481.0, profits: 14099.0 },
10
        { rank: 7, company: 'DaimlerChrysler', revenues: 186106.3, profits: 3536.3 },
11
        { rank: 8, company: 'Toyota Motor', revenues: 185805.0, profits: 12119.6 },
12
        { rank: 9, company: 'Ford Motor', revenues: 177210.0, profits: 2024.0 },
13
        { rank: 10, company: 'ConocoPhillips', revenues: 166683.0, profits: 13529.0 },
14
        { rank: 11, company: 'General Electric', revenues: 157153.0, profits: 16353.0 },
15
        { rank: 12, company: 'Total', revenues: 152360.7, profits: 15250.0 },
16
        { rank: 13, company: 'ING Group', revenues: 138235.3, profits: 8958.9 },
17
        { rank: 14, company: 'Citigroup', revenues: 131045.0, profits: 24589.0 },
18
        { rank: 15, company: 'AXA', revenues: 129839.2, profits: 5186.5 },
19
        { rank: 16, company: 'Allianz', revenues: 121406.0, profits: 5442.4 },
20
        { rank: 17, company: 'Volkswagen', revenues: 118376.6, profits: 1391.7 },
21
        { rank: 18, company: 'Fortis', revenues: 112351.4, profits: 4896.3 },
22
        { rank: 19, company: 'Crédit Agricole', revenues: 110764.6, profits: 7434.3 },
23
        { rank: 20, company: 'American Intl. Group', revenues: 108905.0, profits: 10477.0 }
24
    ];
25
26
    var obj = {
27
        width: "80%",
28
        height: 400,
29
        colModel: [
30
            { title: "", align: 'center',
31
                template: '<button class="btn-primary btn" data-bind="click: $root.showMe.bind($data, ri, rd)">Click Me</button>' 
32
            },
33
            { title: "Company", dataIndx: "company", 
34
                template: '<span data-bind="css: { \'bold_cls\': ri%2==0 }, text: rd.company"></span>' 
35
            },
36
            { title: "Revenues", dataType: "float", dataIndx: "revenues", 
37
                template: '<span data-bind="text: rd.revenues"></span>' 
38
            },
39
            { title: "Profits", dataType: "float", dataIndx: "profits", 
40
                template: '<span data-bind="text: rd.profits"></span>' 
41
            }
42
        ],
43
        resizable: true,
44
        virtualX: true,
45
        title: "Koockoutjs grid",        
46
        scrollModel: { autoFit: true },
47
        dataModel: { data: data }
48
    };
49
    var gridModel = function(){
50
        this.showMe = function(ri, rd){
51
            alert("rowIndx: "+ ri +", company: "+rd.company);
52
        }
53
        this.gridOptions = obj;
54
    };
55
    ko.applyBindings( new gridModel(), document.getElementById('koApp'));
56
});
57