Open In App

jQWidgets jqxGrid exportdata() Method

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 exportdata() method is used to export every row that is loaded inside the displayed jqxGrid into the XLS, XML, CSV, TSV, HTML, or JSON. It does not return anything.

Note: In order to export the data into a PDF, a browser along with HTML5 support is required.

Syntax:

$('Selector').jqxGrid('exportdata', "xml", "jqxGrid");

Parameter Values:

  • dataType: It is the stated type of export. Possible values are ‘xls’, ‘XML’, ‘html’, ‘JSON’, ‘pdf’, ‘tsv’ or ‘CSV’. It is of type String.
  • fileName: It is the stated name of the file. And in case the file name is not given then the displayed jqxGrid must export the loaded data into a local variable. It is of type String.
  • exportHeader: It is an optional parameter that is helpful in specifying if the header of the column is exported or not. However, the column header is exported by the exporter by default. It is of type Boolean.
  • rows: It is the stated array of rows that is to be exported. However, every row is exported by default. In order to export every row the value of this parameter must be set to null. It is an optional parameter of type Array.
  • exportHiddenColumns: It is helpful in specifying if the hidden columns are exported or not. Moreover, the hidden columns are not exported by the exporter by default. It is an optional parameter that is of type Boolean.
  • serverURL: It is helpful in specifying the URL of the export server. The exporter is presented over a server of jQWidgets. It is of type String.
  • charSet: It specifies the set of characters. It is an optional parameter that is of the type String.

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 exportdata() method 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 exportdata() 
            method
        </h3><br />      
        <div id="jqxg"></div>       
        <div>
            <input type="button" 
                   id="jqxBtn" 
                   style="margin-top: 25px" 
                   value="Click here" />
        </div>        
        <div id="log"></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: "210px",
                width: "240px",
                columns: [
                    {
                        text: "Subject Name",
                        datafield: "subjectnames",
                        width: "120px",
                    },
                    {
                        text: "Page No.",
                        datafield: "pagenumber",
                        width: "120px",
                    },
                ],
            });
  
            $("#jqxBtn").jqxButton({
                width: "180px",
                height: "30px",
            });
            $("#jqxBtn").on("click", function () {
                $('#jqxg').jqxGrid('exportdata', "json", "jqxGrid");
                $("#log").text("Data exported to json!");
            });
        });
    </script>
</body>
  
</html>


Output:

 

Example 2: Below is another example that illustrates the jqxGrid exportdata() method 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 exportdata() 
            method
        </h3><br />      
        <div id="jqxg"></div>       
        <div>
            <input type="button" 
                   id="jqxBtn" 
                   style="margin-top: 25px" 
                   value="Click here" />
        </div>        
        <div id="log"></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: "210px",
                width: "240px",
                columns: [
                    {
                        text: "Subject Name",
                        datafield: "subjectnames",
                        width: "120px",
                    },
                    {
                        text: "Page No.",
                        datafield: "pagenumber",
                        width: "120px",
                    },
                ],
            });
  
            $("#jqxBtn").jqxButton({
                width: "180px",
                height: "30px",
            });
            $("#jqxBtn").on("click", function () {
                var ed = $('#jqxg').jqxGrid('exportdata', "html");
                if (ed === null) {
                    $('#log').text("Data not exported!");
                }
                else {
                    $('#log').text("Data exported!");
                }
            });
        });
    </script>
</body>
  
</html>


Output:

 

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads