Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding feature to make inspection of individual records possible #141

Closed
wants to merge 1 commit into from

Conversation

jcampbell1
Copy link

I needed the feature to drilldown to individual records.

Attached is a pull request. I don't think you want to merge this, because it uses a monkey patch, and directly edits the .js file. I tried to edit the .coffee file, but it didn't compile correctly... an issue with the coffee script version.

This code monkey patches the aggregator push function to add the records to the aggregator before reducing. It then binds the underlying records to the elements using $.fn.data.

I have included an example html page that renders the the raw records when clicking on a cell.

I hope this is helpful. Sorry for giving you half-assed code... I am not skilled enough with coffee-script to battle a version issue.

@nicolaskruchten
Copy link
Owner

Thanks for the contribution! I'll study it and see what I can upstream into the coffeescript version :)

@nocquidant
Copy link

Nice! Unfortunately it doesnt work with fractionOf aggregator functions: data, rowKey and colKey are undefined.

@AbdulGool
Copy link

I received an error using this code, the console logs a string "[object Object]" in the case where there is one record, however using 'd[0]' returns only '[' as .data('records') is only returning a string as "[object Object]" instead of an array of objects.

I solved this in the pivot.js file by adding a toJsonString function. Please excuse the placing of my code, im new to this site and find it fairly tedious to simply share my findings.

function toJsonString(aggr) {
var jsonString;
if (aggr.records) {
if (aggr.records.length > 0) {
jsonString = '[';
var recKeys = Object.keys(aggr.records[0]);
jsonString = jsonString + '{';
for (_ii = 0; _ii < aggr.records.length; _ii++) {
var a = recKeys[0];
var a_value = aggr.records[_ii][a];
if (_ii == 0) {
jsonString = jsonString + '"' + a + '":' + '"' + a_value + '"';
}
else {
jsonString = jsonString + ',{"' + a + '":' + '"' + a_value + '"';
}
for (_i = 1; _i < recKeys.length; _i++) {
a = recKeys[_i];
a_value = aggr.records[_ii][a];
jsonString = jsonString + ',"' + a + '":' + '"' + a_value + '"';
}
jsonString = jsonString + '}';
}
jsonString = jsonString + ']';
}
}
return jsonString;
}

}).call(this);

to reduce confusion, I've added the .call(this) statement to represent the function being entered at the end of the script. This function uses an aggregator as parameter to retrieve records and convert to JSON style string of objects

so in the code where you set: td.setAttribute("data-records", aggregator.records);
I instead just call this function to return the JSON string and all works great!
td.setAttribute("data-records", toJsonString(aggregator));

Hope this helps anyone that encountered an issue like mine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants