Need a special offer?Find out if your project fits.
+
All documentation
  • Introduction
  • Connecting to Data Source
  • Browser compatibility
  • Documentation for older versions
  • Integration with jQuery

    This tutorial will help you integrate the pivot table with the jQuery library.

    Run the sample project from GitHub

    Step 1. Download the project

    Download a .zip archive with the sample project or clone it from GitHub with the following command:

    git clone https://github.com/flexmonster/pivot-jquery

    Step 2. See the results

    Open the pivot-jquery/index.html file in the browser to see the result.

    Integrate Flexmonster into a jQuery application

    If you already have a project with jQuery, jump to Step 2. Add Flexmonster. Otherwise, follow the steps below to set up a simple project:

    Step 1. Create a new jQuery project

    1. Create a new folder for the project, e.g. my-jquery-project/.
    2. Create an index.html file inside my-jquery-project/ and include jQuery:
      <!DOCTYPE html>
      <html>
      <head>
      <title>My jQuery/Flexmonster Project</title>
      </head>
      <body>
      <script src="https://cdn.flexmonster.com/lib/jquery.min.js"></script>
      </body>
      </html>

    Step 2. Add Flexmonster

    Add the Flexmonster library to index.html:

    <!DOCTYPE html>
    <html>
      <head>
        <title>My jQuery/Flexmonster Project</title>
      </head>
      <body>
        <script src="https://cdn.flexmonster.com/lib/jquery.min.js"></script>
        <script src="https://cdn.flexmonster.com/flexmonster.js"></script>
      </body>
    </html>

    Step 3. Add a container for Flexmonster

    Create a <div> container for the component:

    <!DOCTYPE html>
    <html>
      <head>
        <title>My jQuery/Flexmonster Project</title>
      </head>
      <body>
        <script src="https://cdn.flexmonster.com/lib/jquery.min.js"></script>
        <script src="https://cdn.flexmonster.com/flexmonster.js"></script>
    
        <div id="pivotContainer">The component will appear here</div>
      </body>
    </html>

    Step 4. Initialize the pivot table

    Add a simple script to embed the component:

    <!DOCTYPE html>
    <html>
      <head>
        <title>My jQuery/Flexmonster Project</title>
      </head>
      <body>
        <script src="https://cdn.flexmonster.com/lib/jquery.min.js"></script>
        <script src="https://cdn.flexmonster.com/flexmonster.js"></script>
    
        <div id="pivotContainer">The component will appear here</div>
        <script>
          var pivot = $("#pivotContainer").flexmonster({
              componentFolder: "https://cdn.flexmonster.com/",            
              toolbar: true
          });
        </script> 
      </body>
    </html>

    Step 5. Load a sample report

    To see some data on the grid, add the report attribute with the report URL:

    <!DOCTYPE html>
    <html>
      <head>
        <title>My jQuery/Flexmonster Project</title>
      </head>
      <body>
        <script src="https://cdn.flexmonster.com/lib/jquery.min.js"></script>
        <script src="https://cdn.flexmonster.com/flexmonster.js"></script>
       
        <div id="pivotContainer">The component will appear here</div>
        <script>
          var pivot = $("#pivotContainer").flexmonster({
              componentFolder: "https://cdn.flexmonster.com/",
              toolbar: true,
              report: "https://cdn.flexmonster.com/reports/report.json"
          });
        </script>
      </body>
    </html>

    Open the index.htmlfile in the browser — the component with a sample report is embedded into your project.

    Check out a sample on JSFiddle. If you have any problems — visit our troubleshooting section.

    Initial jQuery call to embed the component

    $("#pivotContainer").flexmonster({
    componentFolder: String,
    global: GlobalObject,
    width: Number | String,
    height: Number | String,
    report: ReportObject | String,
    toolbar: Boolean,
    customizeCell: Function,
    licenseKey: String
    })

    [starting from version 2.3]

    Embeds the component into the HTML page.
    As a parameter the jQuery call gets #pivotContainer – this is the id of the HTML element that you want to have as the container for the component.
    This method allows you to insert the component into your HTML page and to provide it with all the necessary information for the initialization.

    Starting from version 2.3 you can preset options for all reports using the GlobalObject.

    Note Do not forget to import jQuery and flexmonster.js before you start working with it.

    Parameters

    Parameter/Type Description
    componentFolder
    String
    optional The URL of the component’s folder that contains all the necessary files. It is also used as the base URL for report files, localization files, styles, and images.
    Default value"flexmonster/".
    global
    GlobalObject
    optional Allows you to preset options for all reports. These options can be overridden for specific reports.
    width
    Number | String
    optional The width of the component on the page (either in pixels or as a percentage).
    Default value"100%".
    height
    Number | String
    optional The height of the component on the page (either in pixels or as a percentage).
    Default value: 500.
    report
    ReportObject | String
    optional The property to set a report. It can be an inline ReportObject or a URL to a report. Specify the report as a URL if your report is:
    • Stored in a JSON file.
    • Returned by a server-side script.
    XML reports are also supported for backward compatibility.
    toolbar
    Boolean
    optional The parameter to embed the Toolbar (true) or not (false).
    Default value: false.
    customizeCell
    Function
    optional Allows customizing separate cells. For more info, take a look at customizeCell definition and examples.
    customizeContextMenu
    Function
    optional Allows customizing the context menu. For more info, take a look at customizeContextMenu definition and examples.
    licenseKey
    String
    optional The license key.

    Event handlers can also be set as properties for the jQuery call. Check out the list here.

    All of the parameters are optional. If you run $("#pivotContainer").flexmonster() – an empty component without the Toolbar will be added with the default width and height.

    Returns

    Object - the reference to the embedded pivot table. If you want to work with multiple instances on the same page use these objects. All API calls are available through them.

    After initialization, you can obtain an instance reference to the created component by using this selector:
    var pivot = $("#pivot").data("flexmonster");

    Installation troubleshooting

    If you are facing any problems embedding the component, go to the page where the component should be displayed and open the browser console to check for any errors. Try the following steps:

    • If you get the alert "Flexmonster: jQuery is not loaded.", check the path to jQuery in your HTML page.
    • If the page is blank and you see the following error in the console: "Uncaught TypeError: $(...).flexmonster is not a function", check the path to Flexmonster in your HTML page.
    • If you get the alert "Unable to load dependencies. Please use 'componentFolder' parameter to set the path to 'flexmonster' folder.", add the componentFolder parameter to your $.flexmonster() call (e.g., "https://cdn.flexmonster.com/"):
      <div id="pivotContainer">The component will appear here</div> 
      <script src="https://cdn.flexmonster.com/lib/jquery.min.js"></script>
      <script src="https://cdn.flexmonster.com/flexmonster.js"></script>

      <script>
      var pivot = $("#pivotContainer").flexmonster({
      toolbar: true,
      // set the appropriate path
      componentFolder: "https://cdn.flexmonster.com/",
      });
      </script>
    • If you get the error "Uncaught TypeError: Cannot set property '_generatePosition' of undefined" or something similar, try updating the jQuery UI. The minimum recommended version is 1.9.2.
    • If you get the error "Uncaught TypeError: $.parseXML is not a function" or something similar, try updating jQuery. The minimum recommended version is 1.7.

    What's next?