pqGrid compiles the templates and adds binding context to each of them with following properties:
rd
ri
foreach
7 123<div id="koApp">4 <div data-bind="pqGrid:gridOptions" style="margin:auto;"></div>5</div>67
<div id="koApp">
<div data-bind="pqGrid:gridOptions" style="margin:auto;"></div>
</div>
57 12$(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 ];2526 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
$(function () {
var data = [
{ rank: 1, company: 'Exxon Mobil', revenues: 339938.0, profits: 36130.0 },
{ rank: 2, company: 'Wal-Mart Stores', revenues: 315654.0, profits: 11231.0 },
{ rank: 3, company: 'Royal Dutch Shell', revenues: 306731.0, profits: 25311.0 },
{ rank: 4, company: 'BP', revenues: 267600.0, profits: 22341.0 },
{ rank: 5, company: 'General Motors', revenues: 192604.0, profits: -10567.0 },
{ rank: 6, company: 'Chevron', revenues: 189481.0, profits: 14099.0 },
{ rank: 7, company: 'DaimlerChrysler', revenues: 186106.3, profits: 3536.3 },
{ rank: 8, company: 'Toyota Motor', revenues: 185805.0, profits: 12119.6 },
{ rank: 9, company: 'Ford Motor', revenues: 177210.0, profits: 2024.0 },
{ rank: 10, company: 'ConocoPhillips', revenues: 166683.0, profits: 13529.0 },
{ rank: 11, company: 'General Electric', revenues: 157153.0, profits: 16353.0 },
{ rank: 12, company: 'Total', revenues: 152360.7, profits: 15250.0 },
{ rank: 13, company: 'ING Group', revenues: 138235.3, profits: 8958.9 },
{ rank: 14, company: 'Citigroup', revenues: 131045.0, profits: 24589.0 },
{ rank: 15, company: 'AXA', revenues: 129839.2, profits: 5186.5 },
{ rank: 16, company: 'Allianz', revenues: 121406.0, profits: 5442.4 },
{ rank: 17, company: 'Volkswagen', revenues: 118376.6, profits: 1391.7 },
{ rank: 18, company: 'Fortis', revenues: 112351.4, profits: 4896.3 },
{ rank: 19, company: 'Crédit Agricole', revenues: 110764.6, profits: 7434.3 },
{ rank: 20, company: 'American Intl. Group', revenues: 108905.0, profits: 10477.0 }
];
var obj = {
width: "80%",
height: 400,
colModel: [
{ title: "", align: 'center',
template: '<button class="btn-primary btn" data-bind="click: $root.showMe.bind($data, ri, rd)">Click Me</button>'
},
{ title: "Company", dataIndx: "company",
template: '<span data-bind="css: { \'bold_cls\': ri%2==0 }, text: rd.company"></span>'
{ title: "Revenues", dataType: "float", dataIndx: "revenues",
template: '<span data-bind="text: rd.revenues"></span>'
{ title: "Profits", dataType: "float", dataIndx: "profits",
template: '<span data-bind="text: rd.profits"></span>'
}
],
resizable: true,
virtualX: true,
title: "Koockoutjs grid",
scrollModel: { autoFit: true },
dataModel: { data: data }
};
var gridModel = function(){
this.showMe = function(ri, rd){
alert("rowIndx: "+ ri +", company: "+rd.company);
this.gridOptions = obj;
ko.applyBindings( new gridModel(), document.getElementById('koApp'));
});
x 12.bold_cls3{4 font-weight: bold;5}6
.bold_cls
{
font-weight: bold;