Find file
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (24 sloc) 1.05 KB

is :ExtJS

Add a to_extjs function to any Sequel Dataset, it will generate json that is consumable by the ExtJS JsonStore.

Take a look at Sequel::Plugins::ExtJS::DatasetMethods.to_extjs function for more information.


# this will require the Sequel's ExtJS plugin
require 'sequel_extjs'
# this will add .to_extjs on the Array class, so you can use the same code for datasets and array results
# not required, if you don't like additions to the Array class
require 'array_extjs'

class MyModel < Sequel::Model(:mymodel) 
   is :ExtJS

# now output all MyModel records in a way the JsonStore expects:
# or use any filters before that
MyModel.filter(:status => true).to_exts
# or limit it for pagination
cnt = MyModel.filter(:status => true).count
MyModel.filter(:status => true).limit(10,100).to_extjs(cnt)
# also give it a block and it will more or less work like a 'map'
MyModel.filter(:status => true).to_exts do |rec|
  rec[:newprop] = "Status is #{rec.status}"