Create a Grid from JSON data. For binding to MySQL Database using PHP and server-side sorting, filtering, editing or paging, please visit our Help Documentation.
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.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/data.php";
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'firstname' },
{ name: 'lastname' },
{ name: 'productname'},
{ name: 'quantity', type: 'int' },
{ name: 'price', type: 'float' },
{ name: 'total', type: 'float' }
],
id: 'id',
url: url,
root: 'data'
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#grid").jqxGrid(
{
width: getWidth('Grid'),
source: dataAdapter,
columnsresize: true,
columns: [
{ text: 'First Name', dataField: 'firstname', width: 200 },
{ text: 'Last Name', dataField: 'lastname', width: 200 },
{ text: 'Product', dataField: 'productname', width: 180 },
{ text: 'Quantity', dataField: 'quantity', width: 80, cellsalign: 'right' },
{ text: 'Unit Price', dataField: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
{ text: 'Total', dataField: 'total', cellsalign: 'right', minwidth: 100, cellsformat: 'c2' }
]
});
});
<div id="grid"></div>