GRIDPLUS2 - Date Selector Grid
Home Reference Manpage Examples Download License Contact

GRIDPLUS Date Selector Grid

In order to simplify creation of screen layouts, GRIDPLUS provides a GRIDPLUS dropdown date selector command mode based on the calendar widget. This command mode is a "short cut" method to invoke the GRIDPLUS widget command mode with the default widget set create dateselectors. All of the normal widget command mode functionality can be used. For example creating other widget types.

This uses a simple syntax to create a grid of date selectors. The syntax is closely based on the GRIDPLUS Grid and Widget.

GRIDPLUS Date Selector Specific Item Options/Functionality

See GRIDPLUS Widget Grid for a full list of item options/functionality.

~command
Specifies that a command is invoked when a date is selected from a dropdown date selector calendar. The command name is optional. If not specified command name is based on the name of the date selector.

=default
Specifies the default value to be used for a date selector when the widget is created (See Setting Default Value).

integer
Specifies a positive integer which overrides the default width for the date selector.

GRIDPLUS Date Selector Mouse/Keyboard Bindings

A single left-click anywhere on the date selector, or pressing the down cursor when the widget has focus, will post a dropdown calendar.

A single left-click anywhere on the date selector, or pressing the escape (Esc) key when the widget has focus, will unpost the dropdown calendar.

The following Keys are effective for a date selector field:-

DelClear the content of the date selector field. This option can be disabled using -dateclear.
Cursor DownPost dropdown calendar.
EscUnpost dropdown calendar.

Setting Default Value

Date selector default values can be set to a specified date, today's date -or- a calculated date based on today's date. This option uses the same syntax as gpdate.

=@Date today.
=+daysDate today + days.
=-daysDate today - days.
=>monthsDate today + months.
=<monthsDate today - months.

Example:

gridplus date .mygrid -title "My Grid" -wtitle "Defaults" {
   {"No Default"       .date1}
   {"Today"            .date2 =@}
   {"Add 7 Days"       .date3 =+7}
   {"Add 12 Months"    .date4 =>12}
   {"Subtract 2 days"  .date5 =-2}
   {"Subtract 1 Month" .date6 =<1}
   {"Specified Date"   .date7 =12/25/2011}
}

pack .mygrid

Invoking Commands When a Date is Selected

There are two ways to specify commands to be invoked when a date is selected:-

  1. Specifying the -datecommand (Alias -Dcmd) option when creating a widget grid containing date selectors. This option invokes the specified command for all date selectors in the grid.
  2. Specifying commands for specific entries by using the ~command widget option.

Setting Date Selector Icon

It is possible, using the *Gridplus.dateIcon option database value, to set an icon to replace the down-arrow in the date selector.

Example:

gpoptions dateIcon calendar_view_day
  
gridplus date .mygrid -title "My Grid" -wtitle "Example" {
   {"Date One" .date1}
   {"Date Two" .date2}
}

pack .mygrid

Setting Day and Month Names

Day and month names should be correct for the current locale. If this is not the case use the GRIDPLUS set command/mode to explicitly set the locale.

For Example:

gridplus set -locale de_DE

Example

This section contains an example which illustrates the main GRIDPLUS date selector command mode features.

The following example assumes that the reader is familiar with the contents of the Grid/Layout and Widget pages. Information given on that page will not be duplicated here.

Note: The example assumes that the GRIDPLUS package has already been "required" and the commands imported.


Date Selector Example

Window:

Dropdown calendar posted...

Date selected using mouse...

Source Code:

gridplus date .mygrid -title "My Grid" -wtitle "Example" {
   {"Date One" .date1}
   {"Date Two" .date2}
}

pack .mygrid

Comments:

When using the GRIDPLUS date selector command mode the "label" defines the text that will appear as a label to the associated date selector. The cell item begining with a dot is the widget (date selector) ID. The date selectors are created with names based on the name of the containing Grid and the widget ID.

For example: The for the ".mygrid" cell defined by "{"Date Two" .date2}" a date selector widget is created with the name ".mygrid,date2". Please note that the widget name does contain a comma - this is not a misprint!!

In ".mygrid" the widget IDs are to the right of the label text. This will create date selectors which are to the right of the label text.

Reading and Setting GRIDPLUS Date Selector Values

The values of the GRIDPLUS widgets are stored in a global array with a null name.

For Example:

global {}

For GRIDPLUS Date selector widgets the array element has the same name as the widget: Thus the value of ".date1" in ".mygrid" is referenced as "$(.mygrid,date1)".

The recommended method to set GRIDPLUS date selector values is to use the gpset command.

For Example:

gpset .mygrid,date1 07/12/2009

Note: The date must be in the format as defined by -dateformat. An incorrect format will result in an error when posting a dropdown calendar.


Copyright © 2013 Adrian Davis.