Back to homepage

Cell Data Object

A cellData object contains all the information about the cell.

Properties

NameTypeDescription
columnIndexNumberAn index of the cell’s column.
columnsArray of Hierarchy ObjectsContains the hierarchies from the column associated with the cell.
height NumberDefines a height of the cell.
hierarchy ObjectDefines a hierarchy associated with the cell.
isClassicTotalRowBooleanSpecifies whether the cell contains a subtotal value and is formatted according to the classic form.
isDrillThroughBooleanSpecifies whether the cell belongs to the drill-through view (true) or the grid (false).
isGrandTotalBooleanSpecifies whether the cell contains a grand total value.
isGrandTotalColumnBooleanSpecifies whether the cell contains a grand total value of the column.
isGrandTotalRowBooleanSpecifies whether the cell contains a grand total value of the row.
isTotalBooleanSpecifies whether the cell contains a total value.
isTotalColumnBooleanSpecifies whether the cell contains a total value of the column.
isTotalRowBooleanSpecifies whether the cell contains a total value of the row.
labelStringContains a label of the cell.
levelNumberDefines a level of the hierarchy.
measureObjectDefines a measure associated with the cell.
memberObjectDefines a member associated with the cell.
rowIndexNumberAn index of the cell’s row.
rowsArray of Hierarchy ObjectsContains the hierarchies from the
row associated with the cell.
typeStringDefines a type of the cell. Possible values:
"header" and "value".
valueNumberContains a value of the cell.
widthNumberDefines the width of the cell.
xNumberDefines an absolute X-positioning of the cell on the page
yNumberDefines an absolute Y-positioning of the cell on the page

on(eventName:String, function:Function|String)

Attaches a JavaScript event handler to the specified event. Follow the link to see a full list of events.

Parameters

NameTypeDescription
eventNameStringSpecifies a name of the component’s event.
functionFunction|StringSpecifies a name of a JavaScript function or a function itself that should be an event handler for the specified event.

Example

Add an event handler to the reportchange event:

webdatarocks.on('reportchange', 'onReportChange');

function onReportChange(result) {
alert('The report has been changed!');
}

See the CodePen demo.

See also

off(eventName:String, functionName:String)

Removes JavaScript event handlers that are attached to a pivot table component with the on() method. Follow the link to see a full list of events.

Parameters

NameTypeDescription
eventNameStringoptional The name of the event handler to be removed. If it is not specified, all the event handlers are removed for this event.
functionNameStringoptional The name of the event handler to be removed. If it is not specified, all the event handlers are removed for this event.

Examples

1) Remove all the handlers for the reportchange event:

webdatarocks.off('reportchange');

2) Remove the specified handler for the reportchange event:

webdatarocks.off('reportchange', 'onReportChanged');

Note that if you add the event listener the following way:

webdatarocks.on('reportchange', function () {
alert('The report has been changed!');
});

Then it is not possible to remove such a handler by its name. All that is feasible is to remove all the handlers from an event:

webdatarocks.off('reportchange');

See the CodePen demo.

See also

 

A report object contains all configurations for a pivot table. This includes:

  • which data to show
  • how to show it
  • conditional formatting rules
  • number formatting
  • localization

Properties

Report object has the following properties:

NameTypeDescription
dataSourceData Source ObjectСontains the information about the data source of the report.
sliceSlice Objectoptional Defines which fields should be placed into the rows, columns, and measures. Besides, it contains information about the filtering, sorting, expands, drills and report filtering features.
optionsOptions Objectoptional Defines the view and functionality available for users.
conditionsArray of Conditional Format Objectsoptional Used for defining conditional formatting rules.
formatsArray of Format Objectsoptional Used for defining number formatting in the component.
localizationString|Objectoptional Sets a localization. For more details, refer to language localization tutorial.
tableSizesTable Sizes Objectoptional Stores size settings for columns and rows.

Example of a report

{
dataSource: {
dataSourceType: "csv",
filename: "https://cdn.webdatarocks.com/data/data.csv"
},
slice: {
rows: [
{
uniqueName: "Country"
}
],
columns: [
{
uniqueName: "Color"
},
{
uniqueName: "Measures"
}
],
measures: [
{
uniqueName: "Price",
aggregation: "sum",
format: "currency"
},
{
uniqueName: "Discount",
aggregation: "sum",
format: "currency"
}
]
},
options: {
grid: {
showGrandTotals: "off"
}
},
conditions: [
{
formula: "#value > 350000",
format: {
backgroundColor: "#0598df",
color: "#FFFFFF"
}
},
{
formula: "AND(#value > 1000, #value < 3000)",
format: {
backgroundColor: "#f45328",
color: "#FFFFFF"
}
}
],
formats: [
{
name: "currency",
thousandsSeparator: ",",
decimalPlaces: 2,
currencySymbol: "$",
currencySymbolAlign: "left"
}
],
tableSizes: {
columns: [
{
tuple: [
"Color.blue"
],
measure: "Price",
width: 200
}
],
rows: [
{
idx: 4,
height: 80
}
],
},
localization: "https://cdn.webdatarocks.com/loc/es.json"
}

See also

A dataSource object contains the information about the data source of the report.

Properties

NameTypeDescription
filenameStringoptional The URL to JSON or CSV file. Also can be the URL to the server-side script generating the data.
fieldSeparatorStringoptional Specific field delimiter for CSV data. By default, WebDataRocks can parse comma-separated values or semicolon-separated values. For all other cases, fieldSeparator should be specified.
dataStringoptional Property to specify inline JSON data. See an example.
Read more about supported JSON formats.

Example

Connect to a CSV file in WebDataRocks reporting tool:

var pivot = new WebDataRocks({
container: "#wdr-component",
toolbar: true,
height: 395,
report: {
dataSource: {
filename: "https://cdn.webdatarocks.com/data/data.csv"
}
}
});

Try it out on CodePen.

runQuery(query:Query Object)

Invoke this method on a pivot table instance. It takes a Query Object as an argument and runs it. The Query Object contains a slice with rows, columns, measures, and reportFilters.

Use it if you need to:

  • reorganize the hierarchies on the grid.
  • compose a new report that is based on the current data.

Parameters

NameTypeDescription
queryQuery ObjectContains rows, columns, measures, and reportFilters from a Slice Object.

Example

Suppose you have a pivot table with the following report:

var pivot = new WebDataRocks({
container: "wdr-component",
toolbar: true,
report: {
dataSource: {
filename: "https://cdn.webdatarocks.com/data/data.csv"
},
slice: {
rows: [
{
uniqueName: "Category"
}
],
columns: [
{
uniqueName: "Measures"
},
{
uniqueName: "Country"
}
],
measures: [
{
uniqueName: "Price",
aggregation: "sum"
}
]
}
}
});

If you want to rearrange the hierarchies in a slice dynamically with code, define the following slice and pass it as an argument to the runQuery() method:

var slice = {
rows: [
{
uniqueName: "Country"
}
],
columns: [
{
uniqueName: "Category"
}
],
measures: [
{
uniqueName: "Price",
aggregation: "sum"
}
]
};

webdatarocks.runQuery(slice);

Check out more details in the CodePen demo.

See also

 

getReport(options:Object): Report Object

This method returns a current Report Object from a pivot table component. Use it to save or edit a report.

Parameters

NameTypeDescription
optionsObjectContains the following properties:
  • withDefaults
BooleanSpecifies whether default values of an options object should be included in a report (true) of not (false). Default value: false.
  • withGlobals
BooleanSpecifies whether values of an options object defined in a global object should be included in a report (true) or not (false). Default value: false.

Examples

1) Get a report:

var pivot = new WebDataRocks({
container: "#wdr-component",
toolbar: true,
height: 490,
report: "https://cdn.webdatarocks.com/reports/report.json"
});

function getReport() {
console.log(pivot.getReport());
}

See the CodePen demo.

2) Swap two reports:

<div id="wdr-component1"></div>
<div id="wdr-component2"></div>
<script>
var pivot1 = new WebDataRocks({
container: "#wdr-component1",
toolbar: true,
height: 490,
report: {
dataSource: {
dataSourceType: "csv",
filename: "https://cdn.webdatarocks.com/data/data.csv"
},
slice: {
rows: [
{
uniqueName: "Category"
}
],
columns: [
{
uniqueName: "Measures"
},
{
uniqueName: "Country"
}
],
measures: [
{
uniqueName: "Price",
aggregation: "sum"
}
]
}
}
});

var pivot2 = new WebDataRocks({
container: "#wdr-component2",
toolbar: true,
height: 390,
report: "https://cdn.webdatarocks.com/reports/report.json"
});

function swapReports() {
var report1 = pivot1.getReport();
var report2 = pivot2.getReport();

pivot1.setReport(report2);
pivot2.setReport(report1);
}
</script>

See the CodePen demo.

3) Get report with defaults or globals:

var pivot = new WebDataRocks({
container: "#wdr-component",
toolbar: true,
height: 490,
report: "https://cdn.webdatarocks.com/reports/report.json"
});

function getReportGlobals() {
console.log(pivot.getReport({
withGlobals: true
}));
}

function getReportDefaults() {
console.log(pivot.getReport({
withDefaults: true
}));
}

function getReportGlobalsDefaults() {
console.log(pivot.getReport({
withGlobals: true,
withDefaults: true
}));
}

See the CodePen demo.

setReport(report:Report Object | String)

This method sets a report in a pivot table component. Use it in a combination with a getReport() method or separately.

Parameters

NameTypeDescription
reportObject | StringDefines a report for a pivot table. It’s possible to set either a Report Object or a name of a variable that stores a report definition.

Examples

1) Set a new report:

<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<button onclick="setReport()">Set report</button>
<div id="wdr-component">A pivot table will appear here</div>
<script>
var pivot = new WebDataRocks({
container: "#wdr-component",
height: 395,
customizeCell: customizeCellFunction,
report: "https://cdn.webdatarocks.com/reports/report.json"
});
</script>

<script>
function setReport() {
var report = {
dataSource: {
filename: "https://cdn.webdatarocks.com/data/data.csv"
},
slice: {
rows: [

{
uniqueName: "Category"
},
{
uniqueName: "Color"
}
],
columns: [

{
uniqueName: "Measures"
},
{
uniqueName: "Country"
}
],
measures: [

{
uniqueName: "Price",
aggregation: "sum"
}

]
}
}
pivot.setReport(report);
}
</script>

See the CodePen demo.

2) Swap two reports:

<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<button onclick="javascript: swapReports()">Swap reports</button>
<div id="wdr-component1"></div>
<div id="wdr-component2"></div>
<script>
var pivot1 = new WebDataRocks({
container: "#wdr-component1",
toolbar: true,
height: 490,
report: {
dataSource: {
dataSourceType: "csv",
filename: "https://cdn.webdatarocks.com/data/data.csv"
},
slice: {
rows: [

{
uniqueName: "Category"
}

],
columns: [

{
uniqueName: "Measures"
},
{
uniqueName: "Country"
}
],
measures: [

{
uniqueName: "Price",
aggregation: "sum"
}

]
}
}
});

var pivot2 = new WebDataRocks({
container: "#wdr-component2",
toolbar: true,
height: 390,
report: "https://cdn.webdatarocks.com/reports/report.json"
});

function swapReports() {
var report1 = pivot1.getReport();
var report2 = pivot2.getReport();

pivot1.setReport(report2);
pivot2.setReport(report1);
}
</script>

See the CodePen demo.

WebDataRocks provides users with an extensive JavaScript API for interaction with a pivot table component.

This API reference covers all the details about a component’s objects, methods and events.

Get started with Init API call to embed WebDataRocks into your project.

Objects

Cell Data ObjectContains the information about the cell.
Conditional Format ObjectDefines the conditions for cell formatting.
Data Source ObjectContains the information about the data source.
Format ObjectDefines a custom format for numeric cells.
Global ObjectContains configurations that will be applied to all reports.
Options ObjectDefines the view and functionality of the pivot table.
Report ObjectContains all the configurations of the pivot table.
Slice ObjectContains the information about the hierarchies, filtering, sorting, expands, drills and report filtering.
Table Sizes ObjectStores size settings for columns and rows.

Methods

collapseAllDataCollapses all nodes and drills up all levels of all hierarchies.
customizeCellAllows changing the content and style of separate cells.
expandAllDataExpands all nodes and drills down all levels of all hierarchies.
exportToExports the content from the grid to a file of the chosen format.
getAllConditionsReturns a list of conditional formatting rules from the current report.
getAllHierarchiesReturns a list of available hierarchies from the current report.
getAllMeasuresReturns a list of available measures (both active and inactive) from the current report.
getOptionsReturns an Options Object from a pivot table.
getReportReturns a Report Object from a pivot table.
getCellReturns information about the cell by its row and column indices.
getSelectedCellReturns information about the structure of the cell selected on the grid.
getDataReturns the data from a pivot table. Use it for integration with 3rd party charting libraries.
googlecharts.getDataReturns the data from a pivot table and pre-processes it to the appropriate format of a chart. Use this method for integration with Google Charts.
highcharts.getDataReturns the data from a pivot table and pre-processes it to the appropriate format of a chart. Use this method for integration with Highcharts.
loadLoads a report JSON file from the specified URL to a pivot table.
offRemoves event handlers from the events.
onAttaches an event handler to the specified event.
refreshRedraws a component. Use it to see the applied changes to a report.
removeSelectionClears selection from the cells.
runQueryRuns a query on a pivot table instance.
saveSaves all current report configurations to the specified destination.
setOptionsSets an Options Object of a pivot table.
setReportSets a Report Object of a pivot table.
updateDataConnects to a new data source dynamically without changing report’s configurations.

Events

beforetoolbarcreatedTriggered before the Toolbar initialization. Use it to override the appearance and functionality of the Toolbar.
cellclickTriggered once a user clicks the cell on the grid.
celldoubleclickTriggered once a user double clicks the cell on the grid.
dataloadedTriggered when the data is loaded into the pivot table.
reportchangeTriggered when a report is changed in a component.
reportcompleteTriggered when a report and a localization file are successfully loaded into a pivot table.
updateTriggered when the changes are applied to a pivot table.

update:String

This event is triggered as soon as there were any changes in the component such as:

  • Loading the data from a report and rendering of the grid
  • Loading of the localization file
  • Updating the data slice
  • Filtering of the data.

Use it to retrieve the information about the data source structure.

However, if there is a need to track the changes in a report object, the best practice is to use the reportchange event.

Example

webdatarocks.on('update', function() {
console.log('The component was updated!');
});

Try it in the CodePen demo.

See also

Move up