The Grid's columns and rows in this examples are retrieved from JSON file.
A live JavaScript/jQuery example of jqxGrid, the jQWidgets Grid component, with its complete source code below. It is one of 139 jqxGrid demos for jQuery.
width property – Sets or gets the Grid's width.columns property – Sets the Grid columns.columnsresize property – Enables or disables the columns resizing.source property – Sets and gets the source.beginupdate method – Starts an update operation.endupdate method – Ends the update operation.hideloadelement method – Hides the data loading image.showloadelement method – Shows the data loading image.To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGrid shows the setup step by step.
The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxscrollbar.js, jqxmenu.js, jqxgrid.js, jqxgrid.selection.js, jqxgrid.columnsresize.js, jqxdata.js.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).
$(document).ready(function () {
var url = "../sampledata/rows_and_columns.txt";
// prepare the data
var source =
{
datatype: "json",
url: url
};
var dataAdapter = new $.jqx.dataAdapter(source, {
autoBind: true,
downloadComplete: function (data) {
var columns = data[0].columns;
var rows = data[1].rows;
var gridAdapter = new $.jqx.dataAdapter({
datafields: [
{ name: 'id', type: 'number' },
{ name: 'name', type: 'string' },
{ name: 'type', type: 'string' },
{ name: 'calories', type: 'int' },
{ name: 'totalfat', type: 'string' },
{ name: 'protein', type: 'string' }
],
id: 'id',
localdata: rows
});
$("#grid").jqxGrid('hideloadelement');
$("#grid").jqxGrid('beginupdate', true);
$("#grid").jqxGrid(
{
source: gridAdapter,
columns: columns
});
$("#grid").jqxGrid('endupdate');
}
}
);
$("#grid").jqxGrid(
{
width: getWidth('Grid'),
columnsresize: true
});
$("#grid").jqxGrid('showloadelement');
});
<div id="grid"></div>