Result_set options

Result set are records (documents) displayed as table grid. There are two main option subgroups in the result set.

- columns, which define field names that are displayed in result set.

- action, which define actions that can be performed on every record of result set. Actions are always displayed in the first column of the grid.

 

columns: required

 

Every column has its sequence number. Every sequence must have a name option which defines the name of the field, with some additional optional options.

 

name: required

Name of the field which value will be displayed in cell.
 

style: optional

HTML style string that will be used in definition of HTML table cell.
 

class: optional

HTML class string that will be used in definition of HTML table cell.
 

eval: optional

This option will use a ruby eval method and pass the value of the field to the evaluated string. This of course is very powerful and must be used with caution. So far, there are some reserved keywords that can be used with eval option:
dc_icon4_boolean: will display checked or unchecked box picture for value pairs 1:0, true:false, y:n.

dc_name4_id: with additional parameters of model_name and title field name. Returns title for ID in belongs_to table relation.

dc_name4_value: Will return name for (usually select) field which has choices defined in helpers:label:model_name:choices4_fieldname locale

 

format: optional

Format option is currently used only in conjunction with date/time and numeric fields.
By default, date/time fields are formatted according to locale. This can be overridden by format option. For example: format: '%d.%m.%Y'

For a numeric field, you can specify the number of decimals which will be used for displaying the number. For example: format: N2

Example:

result_set:
  columns:
    10:  
      name: chapter
      style: 'text-align: left; color: red;'
      class: css-class
    20:  
      name: dc_book_id
      eval: dc_name4_id,dc_book,title
    30:  
      name: active
      eval: dc_icon4_boolean
    40:  
      name: status
      eval: dc_name4_value
    50:  
      name: myval
      eval: AnyClass::return_something
    50:
      name: created_date
      format: '%d.%m.%Y'


actions: optional

 

Every record can have its own manipulation actions. Common actions are edit and delete actions, which are defined as standard. In addition to standard action, there is special duplicates action.
 

Example:

result_set:
  actions: standard

  actions:
    1: edit
    2: duplicate
    3: delete

  actions:
    standard: yes
    5:
      type: duplicate
      dup_fields: key, name

 

Duplicate action has an additional option which defines fields, that will have added duplicate_ string into the duplicated document. Why? If there are unique fields in the document, then duplication will fail.

 

And of course, type action options.

 

Example:

result_set:
  actions_width: 100

  actions:
    10:
      type: ajax
      controller: sms
      action: send_test
      icon: sms_test.png
      title: Send test message
      caption: Test

    20:
      type: link
      controller: cmsedit
      action: edit
      formname: sms_view
      table: sms
      icon: view.png
      title: View message
      target: _blank   

 

Some additional options that can be found in result_set.

 

actions_width: optional

The size of actions area is calculated from the number of actions*(width_of_the_icon + 2). But if a text caption is displayed instead of an icon, calculation will not work. actions_width option defines width of area in pixels.

 

filter: optional

When table (collection) is first opened, then result set is unsorted and with filter set to off. When the user enters filter or sorts, record values are saved to the session and reused next time the editor is used. But what if user needs dynamic filter or sort. With filter option, DrgcmsControls method can be called prior to displaying result set. The called method must return a model with scope and order. The method can also return a false value, which indicates that the user cannot access data. An example is shown below.

 

per_page: optional

By default, cmsedit uses pagination with 30 records on a page. This can be altered by per_page option.

 

Example:

result_set:
  filter: filter_active_only
  per_page: 10

# app/controllers/drgcms_controls/sms_controls.rb
module DrgcmsControls::SmsControls
def filter_active_only
  return false unless session[:user_id] # not logged in
  Sms.where(user_id: session[:user_id]).and(active: true)
     .order('date_created desc')
end
end

 

Below are additional options that can be used to control CSS styles and class options of table and rows which construct the browser object. These options are:

 

table_style: optional

table_class: optional
tr_style: optional
tr_class: optional

 

Result for row can also be variable. With eval option, field values can be accessed inside evaluated code as document['value'] or document.value.

 

Example:

result_set:
  table_class: my-table-class
  table_style: 'background-color: #fff; padding: 10px;'
  tr_class: my-tr-class
  tr_style: 
    eval: "document['value'] >= 0 ? 'color: black;' : 'color: red;'"

 


Last update: 26.01.2022