Html Grid
Dynamically set the columns property of the jqxGrid.
Author: http://jqwidgets.com
by Alexey Sharifullin
HTML
<script src="http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/generatedata.js"></script>
<script src="http://jqwidgets.com/public/jqwidgets/jqx-all.js"></script>
<link rel="stylesheet" href="http://jqwidgets.com/public/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="http://jqwidgets.com/public/jqwidgets/styles/jqx.energyblue.css">
<div id='jqxWidget'>
<div id="jqxgrid"></div>
</div>
JavaScript
var data = generatedata(5);
for(var i=0; i < data.length; i++)
data[i].test = {name : i + " Test Name " + i};
var source = {
localdata: data,
datafields: [{
name: 'firstname',
map: 'test>name',
type: 'string'
}, {
name: 'lastname',
type: 'string'
}, {
name: 'productname',
type: 'string'
}, {
name: 'date',
type: 'date'
}, {
name: 'quantity',
type: 'number'
}, {
name: 'price',
type: 'number'
}],
datatype: "array"
};
var columns = [{
text: 'First Name',
datafield: 'firstname',
width: 90
}, {
text: 'Last Name',
datafield: 'lastname',
width: 90
}, {
text: 'Quantity',
columntype: 'template',
datafield: 'quantity',
width: 80,
createeditor: function (row, cellvalue, editor, cellText, width, height) {
// construct the editor.
var inputElement = $("<div class='myeditor'/>").prependTo(editor);
inputElement.jqxNumberInput({
width: width,
height: height,
decimalDigits: 3,
digits: 5,
theme: 'energyblue',
spinButtons: true
});
},
initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
// set the editor's current value. The callback is called each time the editor is displayed.
editor.find('div.myeditor').jqxNumberInput('val', cellvalue);
},
geteditorvalue: function (row, cellvalue, editor) {
alert('METHOD HAS NOT BEEN CALLED');
return editor.find('div.myeditor').jqxNumberInput('val');
},
width: 80,
cellsalign: 'right',
cellsformat: "f3"
}, {
text: 'Product',
datafield: 'productname',
width: 170
}, {
text: 'Order Date',
datafield: 'date',
width: 160,
cellsformat: 'dd-MMMM-yyyy'
}, {
text: 'Unit Price',
...