Array data (Array of row arrays) can be directly passed as the value of data key in dataModel object.
x1
2<div id="grid_array" style="margin:auto;"></div>
3
461
2$(function () {
3var data = [
4['rank', 'company', 'revenue', 'profits'],
5[1, 'Exxon Mobil', '339938.0', '36130.0'],
6[2, 'Wal-Mart Stores', '315654.0', '11231.0'],
7[3, 'Royal Dutch Shell', '306731.0', '25311.0'],
8[4, 'BP', '267600.0', '22341.0'],
9[5, 'General Motors', '192604.0', '-10567.0'],
10[6, 'Chevron', '189481.0', '14099.0'],
11[7, 'DaimlerChrysler', '186106.3', '3536.3'],
12[8, 'Toyota Motor', '185805.0', '12119.6'],
13[9, 'Ford Motor', '177210.0', '2024.0'],
14[10, 'ConocoPhillips', '166683.0', '13529.0'],
15[11, 'General Electric', '157153.0', '16353.0'],
16[12, 'Total', '152360.7', '15250.0'],
17[13, 'ING Group', '138235.3', '8958.9'],
18[14, 'Citigroup', '131045.0', '24589.0'],
19[15, 'AXA', '129839.2', '5186.5'],
20[16, 'Allianz', '121406.0', '5442.4'],
21[17, 'Volkswagen', '118376.6', '1391.7'],
22[18, 'Fortis', '112351.4', '4896.3'],
23[19, 'Crédit Agricole', '110764.6', '7434.3'],
24[20, 'American Intl. Group', '108905.0', '10477.0']];
25
26
27var obj = {
28title: "Grid From Array",
29numberCell: { resizable: true, title: "#" },
30scrollModel: { autoFit: true },
31columnTemplate: {
32title: function (ui) {
33return ['A', 'B', 'C', 'D'][ui.colIndx];
34}
35},
36sortModel: {on : false},
37showBottom: false,
38freezeRows: 1,
39resizable: true,
40dataModel: { data: data }
41};
42
43var $grid = $("#grid_array").pqGrid(obj);
44
45});
46
obj.cellMouseDown = function (evt, ui) { cons.log("mouse down"); var val = ui.dataModel.data[ui.rowIndx][ui.colIndx]; ui.dataModel.mousedown = { rowIndx: ui.rowIndx, colIndx: ui.colIndx, val: val }; } obj.cellMouseMove = function (evt, ui) { if (ui.dataModel.mousedown) { ui.dataModel.data[ui.rowIndx][ui.colIndx] = ui.dataModel.mousedown.val; cons.log("mouse move rowIndx = " + ui.rowIndx + ", colIndx = " + ui.colIndx); $grid.pqGrid("selection", { type: 'cell', method: 'add', rowIndx: ui.rowIndx, colIndx: ui.colIndx }); $grid.pqGrid("refreshCell", { rowIndx: ui.rowIndx, colIndx: ui.colIndx }); } } obj.cellMouseUp = function (evt, ui) { cons.log("mouse up rowIndx = " + ui.rowIndx + ", colIndx = " + ui.colIndx); //get all selection //chnage the values //refresh the column or row. ui.dataModel.mousedown = null; }