edjames / pivot_table Goto Github PK
View Code? Open in Web Editor NEWTransform an ActiveRecord-ish data set into pivot table
License: MIT License
Transform an ActiveRecord-ish data set into pivot table
License: MIT License
Encouraged by the remark 'There are no dependencies and pivot will work on any version of Ruby.' I tried it with Ruby 1.8.7 and it works for me.
I got a warning in the prepare_grid method on the line:
@data_grid << column_headers.count.times.inject([]) { |col| col << nil }
which went away when I replaced it with
@data_grid << column_headers.count.times.inject([]) { }
without any negative effect so far.
Hi!
In the example you have exactly one object for each cell in the resulting pivot table.
But ususally real data contains multiple entries for each cell in a pivot table. So instead of finding and picking the first matching entry in the "source_data" (grid.rb line 78) shouldn't it extract an array with a select method (using the same block)?
Otherwise the user would be forced to accumulate the input data himself and the advantage of this gem is lost.
Greeting.
Jens
Hi
thx for publishing your gem. how do I actually display the table in an html.erb? I can build it but displaying it? I noticed that the build command - this presumably goes into the controller. but what do I put in view template between these tags: <% %> to make the pivot table display?
rgds
Ben
HI
When I do g.build
(in my controller) like your readme mentions I get following error comparison of String with nil failed
. Do you have any idea what could be the problem? I am literally messing with this for hours.
def no_category
@Transactions = Transaction.all.limit(10)
g = grid(@Transactions, { :row_name => :naam_tegenpartij, :column_name => :landcode })
g.build
end
My module code looks like this:
module PivotTableBla
def grid(data, options = {})
grid = PivotTable::Grid.new do |g|
g.source_data = data
g.column_name = options[:column_name]
g.row_name = options[:row_name]
end
end
end
I have data set which has multiple data for a row, column combination. i think currently, it ignores the second value. any solution?
I'm using the following to construct
data = ActiveRecord::Base.connection.execute("SELECT users.name as user_name, leave_types.name as leave_type_name, leave_balances.balance from leave_balances join users on leave_balances.user_id = users.id join leave_types on leave_balances.leave_type_id = leave_types.id")
grid = PivotTable::Grid.new do |g|
g.source_data = data
g.column_name = :leave_type_name
g.row_name = :user_name
g.value_name = :balance
end
This gives me a result like:
[{"user_name"=>"Manager", "leave_type_name"=>"Anltjsjsjs", "balance"=>1.0, 0=>"Manager", 1=>"Anltjsjsjs", 2=>1.0}, {"user_name"=>"Employee",.....
Which fails when I build the grid with errors like:
undefined method `user_name' for #Hash:0x00000103ad0b98
it looks like this should work with an array of hashes, do I need to reformat or select differently somehow?
This is cool. Do you have a quick way to print a grid to the console?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.