class Tabulator(T)
- Tabulator(T)
- Reference
- Object
Overview
This class paginates an Avram query by tabs from A-Z and "#". It's similar to Paginator, but for alphabetical tabs.
Tabulator can be used together with Paginator when there are a lot of records for a particular alphabetical tab.
Defined in:
tabulator.crConstant Summary
-
English =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-
The pre-defined alphabet for English, this is the default.
Constructors
-
.new(letter : String | Nil, query : T, field : String | Symbol, path : String, small : Int32 = 20, alphabet : String = English, collate : String = "POSIX") forall T
Create a Tabulator instance.
Instance Method Summary
-
#html_tabs : String
This generates the simplest form of an html list for the tabs.
-
#record_count : Int64
The count of records that would be returned by query.
-
#selected : Avram::Queryable
Return an unevaluated query for records in which field starts with the letter in letter, independent of case.
-
#tabs
An
Array(Char)
containing all of the letters (in uppercase) for which a record exists, independent of case.
Constructor Detail
Create a Tabulator instance. The letter, query and path arguments must be provided, the rest are optional.
letter is the letter tab currently selected. If this is null or something not in alphabet, this will be the first available tab.
query is the query instance used to get the records to display.
Generally it's something like CompanyQuery.new
. This must be from .new
,
and can have as many criteria to refine the selected records as you choose.
For example, if you've set up pg_trgm
for your database, here's a
trigram search:
CompanyQuery.new.where("name % ?", "Colorado")
path is the prefix of the path for a tab. The letter of the tab, or "#" for records that don't start with a letter, will be added as a suffix to this.
-
To use path parameters, provide a string like
"/test/"
, which will process to"/test/#{letter}"
for the path of the tab. -
To use query paramters, provide a string like
"/test/?page="
, which will process to"/test/?page=#{letter}"
for the path of the tab.
For internationalization, alphabet is the alphabet of your user,
uppercase, in alphabetical order (or the order in which you want them
presented). See English
for an example.
The default will be English
if not provided.
For internationalization, collate is the regional collation string for
the user, like "en_US"
or "POSIX". If this is not set, the default is
"POSIX".
Instance Method Detail
This generates the simplest form of an html list for the tabs. You can provide your own version of this to create a flavor for your particular web toolkit.
The user can surround this with another element, perhaps a div
, and
write CSS for styling tags and classes within that element.
The a
tag has the class content
so that styling for nested lists can
be distinguished from styling for the list created here.
The count of records that would be returned by query. This is the sum of the count of an index-only query for each letter in the alphabet, and "#". Because the query only accesses an index, rather than the records, and it returns one integer; it runs relatively quickly.
Return an unevaluated query for records in which field starts with the
letter in letter, independent of case. If letter is "#"
, return
an unevaluated query of the records in which field begins with something
else than a letter in alphabet. If letter doesn't have any data populated,
replace it with the first tab that does have data populated.
This query can be passed to paginate
if there are enough records that
paginating an alphabetical tab is necessary.
An Array(Char)
containing all of the letters (in uppercase)
for which a record exists, independent of case.
Use this to write a renderer for your own tabs, rather than
use the #html_tabs
method of this class.
If the query would return no records, Tabulator#tabs.size
will be 0.
If Tabulator#tabs.size
is 1, you may wish to take the option of
presenting untabbed data in your view.
To produce this, an index-only query is run for each letter of the alphabet, and "#", returning a count. Because the query only accesses an index, and not the records, and returns one integer; it runs relatively quicky.