gcombobox: combobox implementation

Description Usage Arguments Details Value Note Examples

View source: R/gcombobox.R

Description

The svalue<- method is used to specify value by name or by index.

The name gdroplist is an alternative (not encouraged) for gcombobox

Usage

1
2
3
4
5
6
7
8
9
gcombobox(items, selected = 1, editable = FALSE, coerce.with = NULL,
  handler = NULL, action = NULL, container = NULL, ..., width = NULL,
  height = NULL, ext.args = NULL, autocomplete = FALSE,
  initial.msg = "", tpl = NULL)

gdroplist(items, selected = 1, editable = FALSE, coerce.with = NULL,
  handler = NULL, action = NULL, container = NULL, ..., width = NULL,
  height = NULL, ext.args = NULL, autocomplete = FALSE,
  initial.msg = "", tpl = NULL)

Arguments

items

a vector or data frame of items to choose from. Coerced to character class. Use coerce.with to get a numeric value, say. If a data frame then one can add an icon, tooltip, and possibly extra information: with 1 column (items), two columns (items, icons), or three columns (items, icons, tooltip)). If 4 or more, then extra columns can be incorporated by specifying a template. The icon is a url, not a stock name. For stock icons, convert with getStockIconByName with css=FALSE specified.

selected

initially selected item, by index. Use 0L for none.

editable

logical. Does combobox allow editing. A bug (or package writer's limitations) in extjs do not allow one to set the value if it is a potential index (when items is integer). Go figure. Use 4.0, not 5 if you want numeric values ...

coerce.with

Function. If given, called on value before returning

handler

optional means (to addHandlerChanged) to specify a handler for the default signal. A handler is a function with signature (h,...) where h is a list with components obj referring to the object emitting the signal, action containing values passed to the action argument, and possible other values.

action

Passed to handler to parameterize a call

container

A parent container. In gWidgetsWWW2 a parent container is not optional (though it can be substituted with the parent argument in some circumstances). The parent specifies the widget heirarchy and the ... argument is used to pass along arguments to layout the child component in the parent container. Typically, these are passed to the add method of the parent container.

...

Used to pass along argument to the parent container's add method and possible other arguments to the underlying ference class constructors.

width

width in pixels of component. Sizing in gWidgetsWWW2 is sometimes necessary as the arguments expand and fill are not well implemented.

height

height in pixels of the component.

ext.args

The contructors of gWidgetsWWW2 ultimately call an Ext constructor. The options passed to the Ext constructor may be added to or overridden by use of this argument. Values are passed in as named list components and with values converted into JavaScript objects by asJSObject.

autocomplete

If TRUE, will hide the trigger and make editable. When the user types the matching values are presented. (This is also the default behaviour, but if the object is not editable, only valid values are stored.)

initial.msg

If selected=0, then one can assign an initial message here

tpl

a template for the item. This is an HTML snippet, where the column names, when wrapped in braces, will be substituted for the values. The first three columns have their names normalized to name, icon, tooltip.

Details

The default change handler differs depending whether the field is editable. If not, then the handler is called before the selection is finalized. Otherwise, the handler is called on the "change" event, which is to track "user-initiated change is detected in the value of the field." This does not always fire on selection by an item. To force that, use the add_handler_select method.

Value

an ExtWidget instance

Note

The [<- method is note working. The tpl argument is not working as we'd like.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
w <- gwindow()
sb <- gstatusbar("Powered by gWidgetsWWW and Rook", cont=w)
g <- ggroup(cont=w, horizontal=FALSE)
cb <- gcombobox(state.name, cont=g)
addHandlerChanged(cb, handler=function(h,...) {
galert(paste("You selected ", svalue(h$obj), sep=""), parent=w)
})
## initial message
gcombobox(state.name, cont=g, selected=0, initial.msg="Choose a state...")
## autocomplete
 cb <- gcombobox(state.name, cont=g, autocomplete=TRUE)
## template
w <- gwindow()
g <- gvbox(container=w)
tmp <- "http://upload.wikimedia.org/wikipedia/commons/thumb/"
icons = paste(tmp, c("5/5c/Flag_of_Alabama.svg/22px-Flag_of_Alabama.svg.png",
                     "e/e6/Flag_of_Alaska.svg/22px-Flag_of_Alaska.svg.png",
                     "9/9d/Flag_of_Arizona.svg/22px-Flag_of_Arizona.svg.png"), sep="")
d <- data.frame(name=c("Alabama", "Alaska","Arizona"),
                icon=icons,
                tooltip=c("Audemus jura nostra defendere",
                  "North to the future",
                  "Ditat Deus"
                  ),
                extra=c(
                  "Montgomery",
                  "Juneau",
                  "Phoenix"),
                stringsAsFactors=FALSE)
cb <- gcombobox(d,
                tpl="<img src=\"{icon}\"></img><span data-qtip=\"{tooltip}\"> {name},
                      Capital is <em>{extra}</em></span>",
                cont=g)

gWidgetsWWW2 documentation built on May 2, 2019, 6:10 p.m.