gridx/modules/extendedSelect/Row (version 1.1)

gridx/modules/extendedSelect/_RowCellBase

Provides advanced row selections.

This module provides an advanced way for selecting rows by clicking, swiping, SPACE key, or CTRL/SHIFT CLICK to select multiple rows. This module uses gridx/core/model/extensions/Mark.

Example

  1. Use select api on grid row object obtained from grid.row(i)

    grid.row(1).select(); grid.row(1).deselect(); grid.row(1).isSelected();

  2. Use select api on select.row module

    grid.select.row.selectById(rowId); grid.select.row.deSelectById(rowId); grid.select.row.isSelected(rowId); grid.select.row.getSelected();//[] grid.select.row.clear();

Property Summary

  • enabled If false, this module is disabled.
  • forced An array of module names.
  • grid Reference to the grid
  • holdingCtrl If true, when selecting it'll appear as if the CTRL key is held.
  • holdingShift If true, when selecting it'll appear as if the SHIFT key is held.
  • loaded Indicate when this module is completely loaded.
  • model Reference to the grid model
  • name The API set name of this module.
  • optional An array of module names.
  • required An array of module names.
  • treeMode Whether to apply tri-state selection for child rows.
  • triggerOnCell Whether row will be selected by clicking on cell, false by default

Method Summary

  • arg(argName, defaultValue, validate) This method provides a normalized way to access module arguments.
  • batchConnect() Do a lot of connects in a batch.
  • clear() Deselected all selected rows;
  • connect(obj, e, method, scope, flag) Connect an event handler to an event or function.
  • deselectById(rowId) Deselect rows by id.
  • deSelectByIndex(rowIndex) Deselect a row by index.
  • getAPIPath() This function defines how to access this module's methods from the grid object.
  • getSelected() Get id array of all selected row IDs.
  • isSelected(rowId) Check if the given rows are all selected.
  • load(args, deferStartup) Completely load this module.
  • preload(args) Preload this module.
  • selectById(rowId) Select rows by id.
  • selectByIndex(rowIndex) Select a row by index This function can also select multiple rows. //Select several individual rows: gridx.select.row.selectByIndex(rowIndex1, rowIndex2, rowIndex3, ...); //Select a range of rows: gridx.select.row.selectByIndex([rowStartIndex, rowEndIndex]); //Select multiple ranges of rows: gridx.select.row.selectByIndex([rowStartIndex1, rowEndIndex1], [rowStartIndex2, rowEndIndex2], ...);
  • subscribe(topic, method, scope) Subscribe to a topic.

Event Summary

Properties

enabled

If false, this module is disabled. This parameter is mainly used by DnD to not conflict with selection operations.

forced

An array of module names. All these modules must exist, and have finished loading before this module loads. This property can be omitted.

grid

Reference to the grid

holdingCtrl

If true, when selecting it'll appear as if the CTRL key is held.

holdingShift

If true, when selecting it'll appear as if the SHIFT key is held.

loaded

Indicate when this module is completely loaded.

model

Reference to the grid model

name

The API set name of this module. This name represents the API set that this module implements, instead of this module itself. Two different modules can have the same name, so that they provide two different implementations of this API set. For example, simple row selection and extended row selection are two modules implementing a same set of APIs. They can be used in two different grids in one page (maybe due to different requirements), without worrying about conflicting with eachother. And any module of grid can be replaced by a new implementation without re-writing any other modules. This property is mandatary.

optional

An array of module names. These modules can be absent, but if they do exist, they must be loaded before this module loads. This property can be omitted.

required

An array of module names. These modules must exist, but they can be loaded at any time. This property can be omitted.

treeMode

Whether to apply tri-state selection for child rows.

triggerOnCell

Whether row will be selected by clicking on cell, false by default

Methods

arg(argName, defaultValue, validate)

This method provides a normalized way to access module arguments.

There are two ways to provide module arguments when creating grid. One is to write them in the module declaration object:

var grid = new Grid({
    ......
    modules: [
        {
            moduleClass: gridx.modules.Pagination,
            initialPage: 1      //Put module arguments in module declaration object
        }
    ],
    ......
});

This way is straightforward, but quite verbose. And if user would like to set arguments

for pre-included core modules (e.g. Header, Body), he'd have to explictly declare the module. This would be too demanding for a grid user, so we need another approach. The other way is to treat them as grid arguments:

var grid = new Grid({
    ......
    modules: [
        gridx.modules.Pagination
    ],
    paginationInitialPage: 1,   //Treat module arguments as grid arguments
    ......
});

In this way, there's no need to provide a module declaration object, but one has to tell

grid for which module the arguments is applied. One can simply put the module name at the front of every module argument: "pagination" -- module name

"initialPage" -- module argument
---------------------------------
paginationInitialPage -- module argument treated as grid argument

Note the first letter of the module arugment must be capitalized in the combined argument.

This "arg" method makes it possible to access module arguments without worring about where they are declared. The priority of every kinds of declarations are: Module argument > Grid argument > default value > Base class argument (inherited) After this method, the argument will automatically become module argument. But it is still recommended to alway access arguments by this.arg(...);

ParameterTypeDescription
argNameString

The name of this argument. This is the "short" name, not the name prefixed with module name.

defaultValueanything
Optional.

This value will by asigned to the argument if there's no user provided values.

validateFunction
Optional.

This is a validation function and it must return a boolean value. If the user provided value can not pass validation, the default value will be used. Note if this function is provided, defaultValue must also be provided.

Returns: any

The value of this argument.

batchConnect()

Do a lot of connects in a batch.

This method is used to optimize code size.

clear()

Deselected all selected rows;

connect(obj, e, method, scope, flag)

Connect an event handler to an event or function.

Similar to widget.connect, the scope of the listener will be default to this module. But in this API, the scope argument is placed behind the listener function, so as to avoid arguemnt checking logic. This method also allows conditional event firing using the flag argument.

ParameterTypeDescription
objObject
eString
methodString | Function
scopeObject
Optional.
flagAnything

If provided, the listener will only be triggered when grid._eventFlags[e] is set to flag.

Returns: any

The connect handle

deselectById(rowId)

Deselect rows by id.

ParameterTypeDescription
rowIdString...

Row ID

deSelectByIndex(rowIndex)

Deselect a row by index. This function can also deselect multiple rows. Please refer to selectByIndex().

ParameterTypeDescription
rowIndexInteger...

Row visual indexes

getAPIPath()

This function defines how to access this module's methods from the grid object.

The returned object of this function will be "recursively" mixed into the grid object. That is, any property of object type in grid will be preserved. For example, if this function returns { abc: { def: 'ghi'} }, and the grid already has a property called "abc", and grid.abc is { jkl: 'mno'}. Then after mixin, grid.abc will still have this jkl property:

{
    abc: {
        jkl: 'mno',
        def: 'ghi'
    }
}

This mechanism makes it possible for different modules to provide APIs to a same sub-API object.

Sub-API object is used to provide structures for grid APIs, so as to avoid API conflicts as much as possible. This function can be omitted.

getSelected()

Get id array of all selected row IDs.

isSelected(rowId)

Check if the given rows are all selected.

ParameterTypeDescription
rowIdString

The ID of a row.

Returns: any

True if all given columns are selected; false if not.

load(args, deferStartup)

Completely load this module.

This is the formal loading process of this module. This function will not be called until all the "forced" and existing "optional" modules are loaded. When the loading process of this module is finished (Note that this might be an async process), this.loaded.callback() must be called to tell any other modules that depend on this module.

ParameterTypeDescription
argsundefined
deferStartupundefined
preload(args)

Preload this module.

If this function exists, it is called after all modules are created ("new"-ed), but not yet loaded. At this time point, all the module APIs are already accessable, so all the mothods of those modules that do not need to load can be used here. Note that this function is not the "load" process, so the module dependancy is not honored. For example, if module A forcedly depends on module B, it is still possible that module A.preload is called before module B.preload. This function can be omitted.

ParameterTypeDescription
argsundefined
selectById(rowId)

Select rows by id.

ParameterTypeDescription
rowIdString...

Row IDs

selectByIndex(rowIndex)

Select a row by index This function can also select multiple rows.

//Select several individual rows:
gridx.select.row.selectByIndex(rowIndex1, rowIndex2, rowIndex3, ...);
//Select a range of rows:
gridx.select.row.selectByIndex([rowStartIndex, rowEndIndex]);
//Select multiple ranges of rows:
gridx.select.row.selectByIndex([rowStartIndex1, rowEndIndex1], [rowStartIndex2, rowEndIndex2], ...);
ParameterTypeDescription
rowIndexInteger...

Row visual indexes

subscribe(topic, method, scope)

Subscribe to a topic.

This is similar to widget.subscribe, except that the "scope" argument in this method is behind the listener function.

ParameterTypeDescription
topicundefined
methodundefined
scopeundefined
Returns: any

The subscription handle

Events

onHighlightChange()

Fired when row highlight is changed.

onSelectionChange(newSelectedIds, oldSelectedIds)

Fired when the selection is changed.

ParameterTypeDescription
newSelectedIdsString[]

Current selected ids.

oldSelectedIdsString[]

Previous selected ids.