This tutorial will help you integrate the pivot table with the jQuery library.
To get our sample project, download it as ZIP or clone it with the following command:
git clone https://github.com/flexmonster/pivot-jquery
Open the pivot-jquery/index.html
file in the browser to see the result.
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:
my-jquery-project/
.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>
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>
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>
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>
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.html
file in the browser — the component with a sample report is embedded into your project. If you have any problems — visit our troubleshooting section.
$("#pivotContainer").flexmonster({
componentFolder
: String,
global
: GlobalObject,
width
: Number | String,
height
: Number | String,
report
: ReportObject | String,
toolbar
: Boolean,
customizeCell
: Function,
licenseKey
: String
})
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.
Note Do not forget to import jQuery
and flexmonster.js
before you start working with it.
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:
|
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.
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");
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:
"Flexmonster: jQuery is not loaded."
, check the path to jQuery in your HTML page."Uncaught TypeError: $(...).flexmonster is not a function"
, check the path to Flexmonster in your HTML page."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>
"Uncaught TypeError: Cannot set property '_generatePosition' of undefined"
or something similar, try updating the jQuery UI. The minimum recommended version is 1.9.2."Uncaught TypeError: $.parseXML is not a function"
or something similar, try updating jQuery. The minimum recommended version is 1.7.