Custom Elements Documentation

Getting Started

jqxDataTable is a HTML Element which displays a table of data and allows the user to sort, filter or edit it.

Every UI element from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.

The first step is to create html page and add links to the javascript files and css dependencies to your project.

The jqxDataTable element requires the following files:

<script type="text/javascript" src="../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.export.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxscrollbar.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxmenu.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxradiobutton.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcheckbox.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxlistbox.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdropdownlist.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdatatable.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxtreegrid.js"></script>
The next step is to add the html element within the body of the html page.

<jqx-data-table settings="elementSettings"></jqx-data-table>
The last step is to initialize the element settings:
<script type="text/javascript">
JQXElements.settings["elementSettings"] =
{
pageable:true,pagerButtonsCount:10, source:adapter,columnsResize:true, columns:columns,altRows:true, theme:"light"
}
</script>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxDataTable's instance.
<script>
window.onload = function () {
var element = document.querySelector("jqx-data-table");
element.addRow(10,{},'first');
}
</script>
To get the result of a function after calling it, you can use the following syntax:
<script>
window.onload = function () {
var element = document.querySelector("jqx-data-table");
var result = element.exportData();
}
</script>
To set a property(option), you need to use the property name and value(s) along with the jqxDataTable's instance.
window.onload = function() {
document.querySelector("jqx-data-table").altRows = false;
}
You can also set properties of HTML Elements by using Attributes. Traditionally, attributes are used to set the initial state of an element. Properties with camelCase naming have dash-based attributes. For example: A property "dataSource" will have an attribute called "data-source".

To get a property(option), you need to use the property name along with the jqxDataTable's instance.
window.onload = function() {
var propertyValue = document.querySelector("jqx-data-table").altRows;
}

Event binding can be defined in the HTML as an attribute. The syntax is: 'on-' and the event's name. Event Names with camelCase naming have dash-based attributes. The attribute's value is the event handler's name. The addEventListener function can also be used for event binding.

<script>
window.onload = function () {
var element = document.querySelector("jqx-data-table");
element.addEventListener("bindingComplete", function(event){
// Your code here
});
}
</script>

Example

<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>DataTable Custom Element</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.light.css" type="text/css" />
<link rel="stylesheet" href="../../styles/demos.css" type="text/css" />
<script type="text/javascript" src="../../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxdatatable.js"></script>
<script type="text/javascript">
var adapter = new jqx.dataAdapter({
dataType: "json",
dataFields: [
{ name: 'name', type: 'string' },
{ name: 'type', type: 'string' },
{ name: 'calories', type: 'int' },
{ name: 'totalfat', type: 'string' },
{ name: 'protein', type: 'string' }
],
id: 'id',
url: "../sampledata/beverages.txt"
});
var columns = [
{ text: 'Name', dataField: 'name', width: 300 },
{ text: 'Beverage Type', dataField: 'type', width: 300 },
{ text: 'Calories', dataField: 'calories', width: 180 },
{ text: 'Total Fat', dataField: 'totalfat', width: 120 },
{ text: 'Protein', dataField: 'protein' }
];
JQXElements.settings["dataTableSettings"] =
{
pageable:true,pagerButtonsCount:10, source:adapter,columnsResize:true, columns:columns,altRows:true, theme:"light"
}
</script>
</head>
<body>
<jqx-data-table settings="dataTableSettings"></jqx-data-table>
</body>
</html>

The result of the above code is: