Open In App

jQWidgets jqxGrid columns Property

Last Updated : 29 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

jQWidgets is a JavaScript framework for making web-based applications for PC and mobile devices. It is a very powerful, optimized, platform-independent, and widely supported framework. The jqxGrid is used to illustrate a jQuery widget that shows data in tabular form. Moreover, it renders full support for connecting with data, as well as paging, grouping, sorting, filtering, and editing.

The columns property is used to set the columns of the displayed jqxGid. It is of array type and its default value is [].

Some properties of the column are as follows:

  • datafield: It is the specified data field of the column.
  • text: It is the specified column name.
  • displayfield: It displays the field of the specified column.
  • sortable: It states if the column is sortable or not.
  • filterable: It states if the column is filterable or not.
  • filter: It sets the column’s initialization filter.
  • columngroup: It determines the name of the column’s parent group.
  • enabletooltips: It determines whether tooltips are enabled.
  • exportable: It states if the column is exportable or not.
  • editable: It states if the column is editable or not.
  • groupable: It states if the column is groupable or not.
  • resizable: It states if the column is resizable or not.
  • draggable: It states if the column is draggable or not.
  • classname: It defines the class name.
  • cellclassname: It defines the class name of the cell.
  • width: It defines the width of the stated column.
  • menu: It defines if the column has a pop-up menu or not.

Syntax:

  • Set the columns property.
$('Selector').jqxGrid({ column: [] });
  • Return the columns property.
var columns = $('Selector').jqxGrid('columns');

Linked Files: Download jQWidgets from the given link. In the HTML file, locate the script files in the downloaded folder.

<link rel=”stylesheet” href=”jqwidgets/styles/jqx.base.css” type=”text/css” />
<script type=”text/javascript” src=”scripts/jquery-1.11.1.min.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxcore.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqx-all.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/jqxmenu.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxgrid.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxgrid.selection.js”></script>

Example 1: The below example illustrates the jqxGrid columns property in jQWidgets.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet"
          href="jqwidgets/styles/jqx.base.css" 
          type="text/css" />
    <script type="text/javascript" 
            src="scripts/jquery-1.11.1.min.js">
    </script>
    <script type="text/javascript" 
            src="jqwidgets/jqxcore.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/jqxmenu.js">
    </script>
    <script type="text/javascript" 
            src="jqwidgets/jqxgrid.js">
    </script>
    <script type="text/javascript" 
            src="jqwidgets/jqxgrid.selection.js">
    </script>
      <script type="text/javascript" 
            src="jqwidgets/jqxgrid.columnsresize.js">
    </script>
</head>
  
<body>
    <center>
        <h1 style="color: green">
            GeeksforGeeks
        </h1>
        <h3>
            jQWidgets jqxGrid columns property
        </h3><br />
        <div id="jqxg"></div>
    </center>
  
    <script type="text/javascript">
        $(document).ready(function () {
            var d = new Array();
            var subjectNames =
                ["C++", "Scala", "Java", "C", "R", "JavaScript"];
  
            var pageNumber =
                ["7", "8", "12", "11", "10", "19"];
  
            for (var j = 0; j < 50; j++) {
                var r = {};
                r["subjectnames"] =
                    subjectNames[(Math.floor(Math.random() * subjectNames.length))];
  
                r["pagenumber"] =
                    pageNumber[(Math.floor(Math.random() * pageNumber.length))];
                d[j] = r;
  
            }
            var src = {
                localdata: d,
                datatype: "array",
            };
            var data_Adapter = new $.jqx.dataAdapter(src);
            $("#jqxg").jqxGrid({
                source: data_Adapter,
                theme: 'energyblue',
                filterable: true,
                height: "240px",
                width: "240px",
                columns: [
                    {
                        text: "Subject Name",
                        columntype: "textbox",
                        filtertype: "input",
                        datafield: "subjectnames",
                        width: "120px",
                    },
                    {
                        text: "Page No.",
                        datafield: "pagenumber",
                        filtertype: "checkedlist",
                        width: "120px",
                    },
                ],
            });
        });
    </script>
</body>
  
</html>


Output:

 

Example 2: Below is another example that illustrates the jqxGrid columns property in jQWidgets by setting its value as []. Here, no data is loaded as the column field is empty.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet"
          href="jqwidgets/styles/jqx.base.css" 
          type="text/css" />
    <script type="text/javascript" 
            src="scripts/jquery-1.11.1.min.js">
    </script>
    <script type="text/javascript" 
            src="jqwidgets/jqxcore.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/jqxmenu.js">
    </script>
    <script type="text/javascript" 
            src="jqwidgets/jqxgrid.js">
    </script>
    <script type="text/javascript" 
            src="jqwidgets/jqxgrid.selection.js">
    </script>
      <script type="text/javascript" 
            src="jqwidgets/jqxgrid.columnsresize.js">
    </script>
</head>
  
<body>
    <center>
        <h1 style="color: green">
            GeeksforGeeks
        </h1>
        <h3>
            jQWidgets jqxGrid columns property
        </h3><br />
        <div id="jqxg"></div>
    </center>
  
    <script type="text/javascript">
        $(document).ready(function () {
            var d = new Array();
            var subjectNames =
                ["C++", "Scala", "Java", "C", "R", "JavaScript"];
  
            var pageNumber =
                ["7", "8", "12", "11", "10", "19"];
  
            for (var j = 0; j < 50; j++) {
                var r = {};
                r["subjectnames"] =
                    subjectNames[(Math.floor(Math.random() * subjectNames.length))];
  
                r["pagenumber"] =
                    pageNumber[(Math.floor(Math.random() * pageNumber.length))];
                d[j] = r;
  
            }
            var src = {
                localdata: d,
                datatype: "array",
            };
            var data_Adapter = new $.jqx.dataAdapter(src);
            $("#jqxg").jqxGrid({
                source: data_Adapter,
                theme: 'energyblue',
                height: "240px",
                width: "240px",
                columns: [],
            });
        });
    </script>
</body>
  
</html>


Output:

 

Reference: https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxgrid/jquery-grid-api.htm?search=



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads