abgov / ab-compensation-transparency-toolkit

Open Source toolkit to support disclosures under Alberta's Public Sector Compensation Transparency Act
Other
6 stars 2 forks source link

Add Customization Callback #7

Open thefire opened 8 years ago

thefire commented 8 years ago

Hello,

This is a very handy toolkit for ensuring compliance with the new compensation transparency act! I just have one suggestion...

Can you add the ability to specify a customization callback function? It could be specified as simply as the csv url (by setting a variable before including the script).

My main reason is that the PublicSectorBody column is optional if you are only reporting on one body and therefore it would be very nice to have a simple way to execute the following line:

$("#grid").jsGrid("fieldOption", "PublicSectorBody", "visible", false);

Also when trying to fit the grid into tighter layouts it would also be very handy to be able to tweak the column widths like so:

$("#grid").jsGrid("fieldOption", "Compensation", "width", "15%");

So, for example, if you added these 3 lines to the end of the loadGrid method:

if ( gridLoadedCallback != undefined) {
   gridLoadedCallback();
}

Then users could do the following before including the script:

<script type="text/javascript">
   var csv = "custom_url/disclosure.csv"; 
   var gridLoadedCallback = function() {
      // hide unnecessary columns
      $("#grid").jsGrid("fieldOption", "PublicSectorBody", "visible", false);
      // fix the width of smaller columns
      $("#grid").jsGrid("fieldOption", "Compensation", "width", "15%");
      $("#grid").jsGrid("fieldOption", "Other", "width", "13%");
      $("#grid").jsGrid("fieldOption", "Severance", "width", "13%");
   }
</script>

Again thanks for the handy and simple toolkit.

Charles Smith Developer/Analyst MacEwan University

devin-serink commented 8 years ago

Hi Charles,

Your approach looks good. However, one complication you'll run into - as it stands we create and pass the grid's config structure in one call, leaving no room to edit it before it's initialized. Not a big deal, since a refresh will take care of such changes, but the grid library can be fussy about widths, and it would be cleaner to get any such customization in place before we call .jsGrid(...).

This is easily achieved if we pull the data structure out of that method and instead write it to a variable, then make the callback (passing the new config variable as an argument to be modified and returned), and then update itself from the return value before finally passing it to jsGrid().

If you're comfortable making these changes, you're welcome to put in a pull request and we'll merge it and put it out as a minor update.

thefire commented 8 years ago

Sure I'll give it a go. Thanks.

thefire commented 8 years ago

I'm pretty new to GitHub so please let me know if I messed up the pull request in any way.

devin-serink commented 8 years ago

Looks great - I've merged it into master. We'll test it out a little then apply it (along with an incoming css fix for an issue that shows up when you have >15 pages worth of data) to the "cdn" version in the gh-pages branch that the toolkit guide directs everyone to, and then document it.