Print Friendly

Class Ext.grid.Grid

Package:Ext.grid
Class:Grid
Extends:Observable
Subclasses:EditorGrid
Defined In:Grid.js
This class represents the primary interface of a component based grid control.

Usage:
var grid = new Ext.grid.Grid("my-container-id", {
     ds: myDataStore,
     cm: myColModel,
     selModel: mySelectionModel,
     autoSizeColumns: true,
     monitorWindowResize: false,
     trackMouseOver: true
 });
 // set any options
 grid.render();
Common Problems:
- Grid does not resize properly when going smaller: Setting overflow hidden on the container element will correct this
- If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element dimensions. The grid adapts to your container's size, if your container has no size defined then the results are unpredictable.
- Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the grid to calculate dimensions/offsets.

Properties   -  Methods   -  Events   -  Config Options

Public Properties

Property Defined By
  ddText : String Grid
Configures the text is the drag proxy (defaults to "%0 selected row(s)"). %0 is replaced with the number of selected ...

Public Methods

Method Defined By
  Grid(String/HTMLElement/Ext.Element container, Object config) Grid
  addEvents(Object object) : void Observable
Copies any events from the passed object onto this object if they do not already exist. The passed object must also ...
  addListener(String eventName, Function handler, [Object scope], [Object options]) : void Observable
Appends an event handler to this component
  autoSize() : void Grid
Causes the grid to manually recalculate its dimensions. Generally this is done automatically, but if manual update is...
  destroy(Boolean removeEl) : void Grid
Destroy this grid.
  fireEvent(String eventName, Object... args) : Boolean Observable
Fires the specified event with the passed parameters (minus the event name).
  getColumnModel() : ColumnModel Grid
Returns the grid's ColumnModel.
  getDataSource() : DataSource Grid
Returns the grid's DataSource.
  getDragDropText() : String Grid
Called to get grid's drag proxy text, by default returns this.ddText.
  getSelectionModel() : SelectionModel Grid
Returns the grid's SelectionModel.
  getView() : GridView Grid
Returns the grid's GridView object.
  hasListener(String eventName) : Boolean Observable
Checks to see if this object is currently listening for a specified event
  on(String eventName, Function handler, [Object options]) : void Observable
Appends an event handler to this element (shorthand for addListener)
  purgeListeners() : void Observable
Removes all listeners for this object
  removeListener(String eventName, Function handler, [Object scope]) : void Observable
Removes a listener
  render() : Ext.grid.Grid Grid
* Called once after all setup has been completed and the grid is ready to be rendered.
  un(String eventName, Function handler, [Object scope]) : void Observable
Removes a listener (shorthand for removeListener)

Public Events

Event Defined By
  bodyscroll : (Number scrollLeft, Number scrollTop) Grid
Fires when the body element is scrolled
  cellclick : (Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e) Grid
Fires when a cell is clicked
  cellcontextmenu : (Grid this, Number rowIndex, Number cellIndex, Ext.EventObject e) Grid
Fires when a cell is right clicked
  celldblclick : (Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e) Grid
Fires when a cell is double clicked
  click : (Ext.EventObject e) Grid
The raw click event for the entire grid.
  columnmove : (Number oldIndex, Number newIndex) Grid
Fires when the user moves a column
  columnresize : (Number columnIndex, Number newSize) Grid
Fires when the user resizes a column
  contextmenu : (Ext.EventObject e) Grid
The raw contextmenu event for the entire grid.
  dblclick : (Ext.EventObject e) Grid
The raw dblclick event for the entire grid.
  dragdrop : (Grid this, Ext.GridDD dd, String targetId, event e) Grid
Fires when dragged row(s) are dropped on a valid DD target
  dragenter : (Grid this, Ext.GridDD dd, String targetId, event e) Grid
Fires when the dragged row(s) first cross another DD target while being dragged
  dragout : (Grid this, Ext.GridDD dd, String targetId, event e) Grid
Fires when the dragged row(s) leave another DD target while being dragged
  dragover : (Grid this, Ext.GridDD dd, String targetId, event e) Grid
Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dr...
  enddrag : (Grid this, Ext.GridDD dd, event e) Grid
Fires when a drag operation is complete
  headerclick : (Grid this, Number columnIndex, Ext.EventObject e) Grid
Fires when a header is clicked
  headercontextmenu : (Grid this, Number columnIndex, Ext.EventObject e) Grid
Fires when a header is right clicked
  headerdblclick : (Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e) Grid
Fires when a header cell is double clicked
  keydown : (Ext.EventObject e) Grid
The raw keydown event for the entire grid.
  keypress : (Ext.EventObject e) Grid
The raw keypress event for the entire grid.
  mousedown : (Ext.EventObject e) Grid
The raw mousedown event for the entire grid.
  mouseout : (Ext.EventObject e) Grid
The raw mouseout event for the entire grid.
  mouseover : (Ext.EventObject e) Grid
The raw mouseover event for the entire grid.
  mouseup : (Ext.EventObject e) Grid
The raw mouseup event for the entire grid.
  rowclick : (Grid this, Number rowIndex, Ext.EventObject e) Grid
Fires when a row is clicked
  rowcontextmenu : (Grid this, Number rowIndex, Ext.EventObject e) Grid
Fires when a row is right clicked
  rowdblclick : (Grid this, Number rowIndex, Ext.EventObject e) Grid
Fires when a row is double clicked
  startdrag : (Grid this, Ext.GridDD dd, event e) Grid
Fires when row(s) start being dragged

Config Options

Config Options Defined By
  A : Object Grid
javascript RegExp defining tagNames allowed to have text selection (Defaults to /INPUT|TEXTAREA|SELECT/i).
  An : Object Grid
Ext.LoadMask config or true to mask the grid while loading (defaults to false).
  If : Boolean Grid
autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of rows measured to get a columns size - defa...
  The : Object Grid
Ext.grid.GridView used by the grid. This can be set before a call to render().
  True : Boolean Grid
to fit the height of the grid container to the height of the data. Defaults to false.

Property Details

ddText

public String ddText
Configures the text is the drag proxy (defaults to "%0 selected row(s)"). %0 is replaced with the number of selected rows.
This property is defined by Grid.

Constructor Details

Grid

public function Grid(String/HTMLElement/Ext.Element container, Object config)
Parameters:
  • container : String/HTMLElement/Ext.Element
    The element into which this grid will be rendered - The container MUST have some type of size defined for the grid to fill. The container will be automatically set to position relative if it isn't already.
  • config : Object
    A config object that sets properties on this grid.

Method Details

addEvents

public function addEvents(Object object)
Copies any events from the passed object onto this object if they do not already exist. The passed object must also inherit from Observable for this method to have any effect.
Parameters:
  • object : Object
    The object from which to copy events
Returns:
  • void
This method is defined by Observable.

addListener

public function addListener(String eventName, Function handler, [Object scope], [Object options])
Appends an event handler to this component
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The method the event invokes
  • scope : Object
    (optional) The scope in which to execute the handler function. The handler function's "this" context.
  • options : Object
    (optional) An object containing handler configuration properties. This may contain any of the following properties:
    • scope {Object} The scope in which to execute the handler function. The handler function's "this" context.
    • delegate {String} A simple selector to filter the target or look for a descendant of the target
    • stopEvent {Boolean} True to stop the event. That is stop propagation, and prevent the default action.
    • preventDefault {Boolean} True to prevent the default action
    • stopPropagation {Boolean} True to prevent event propagation
    • normalized {Boolean} False to pass a browser event to the handler function instead of an Ext.EventObject
    • delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.
    • single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.
    • buffer {Number} Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place.

    Combining Options
    Using the options argument, it is possible to combine different types of listeners:

    A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)

    Code:
    el.on('click', this.onClick, this, { single: true, delay: 100, stopEvent : true, forumId: 4 });

    The method also allows for a single argument to be passed which is a config object containing properties which specify multiple handlers.

    Attaching multiple handlers in 1 call
    Code:

    el.on({ 'click' : { fn: this.onClick scope: this, delay: 100 }, 'mouseover' : { fn: this.onMouseOver scope: this }, 'mouseout' : { fn: this.onMouseOut scope: this } });

    Or a shorthand syntax:
    Code:

    el.on({ 'click' : this.onClick, 'mouseover' : this.onMouseOver, 'mouseout' : this.onMouseOut scope: this });
Returns:
  • void
This method is defined by Observable.

autoSize

public function autoSize()
Causes the grid to manually recalculate its dimensions. Generally this is done automatically, but if manual update is required this method will initiate it.
Parameters:
  • None.
Returns:
  • void
This method is defined by Grid.

destroy

public function destroy(Boolean removeEl)
Destroy this grid.
Parameters:
  • removeEl : Boolean
    True to remove the element
Returns:
  • void
This method is defined by Grid.

fireEvent

public function fireEvent(String eventName, Object... args)
Fires the specified event with the passed parameters (minus the event name).
Parameters:
  • eventName : String
  • args : Object...
    Variable number of parameters are passed to handlers
Returns:
  • Boolean
    returns false if any of the handlers return false otherwise it returns true
This method is defined by Observable.

getColumnModel

public function getColumnModel()
Returns the grid's ColumnModel.
Parameters:
  • None.
Returns:
  • ColumnModel
This method is defined by Grid.

getDataSource

public function getDataSource()
Returns the grid's DataSource.
Parameters:
  • None.
Returns:
  • DataSource
This method is defined by Grid.

getDragDropText

public function getDragDropText()
Called to get grid's drag proxy text, by default returns this.ddText.
Parameters:
  • None.
Returns:
  • String
This method is defined by Grid.

getSelectionModel

public function getSelectionModel()
Returns the grid's SelectionModel.
Parameters:
  • None.
Returns:
  • SelectionModel
This method is defined by Grid.

getView

public function getView()
Returns the grid's GridView object.
Parameters:
  • None.
Returns:
  • GridView
This method is defined by Grid.

hasListener

public function hasListener(String eventName)
Checks to see if this object is currently listening for a specified event
Parameters:
  • eventName : String
    The name of the event to check for
Returns:
  • Boolean
    True if the event is being listened for, else false
This method is defined by Observable.

on

public function on(String eventName, Function handler, [Object options])
Appends an event handler to this element (shorthand for addListener)
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The method the event invokes
  • options : Object
    (optional)
Returns:
  • void
This method is defined by Observable.

purgeListeners

public function purgeListeners()
Removes all listeners for this object
Parameters:
  • None.
Returns:
  • void
This method is defined by Observable.

removeListener

public function removeListener(String eventName, Function handler, [Object scope])
Removes a listener
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The handler to remove
  • scope : Object
    (optional) The scope (this object) for the handler
Returns:
  • void
This method is defined by Observable.

render

public function render()
* Called once after all setup has been completed and the grid is ready to be rendered.
Parameters:
  • None.
Returns:
  • Ext.grid.Grid
    this
This method is defined by Grid.

un

public function un(String eventName, Function handler, [Object scope])
Removes a listener (shorthand for removeListener)
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The handler to remove
  • scope : Object
    (optional) The scope (this object) for the handler
Returns:
  • void
This method is defined by Observable.

Event Details

bodyscroll

public event bodyscroll
Fires when the body element is scrolled
Subscribers will be called with the following parameters:
  • scrollLeft : Number
  • scrollTop : Number
This event is defined by Grid.

cellclick

public event cellclick
Fires when a cell is clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • rowIndex : Number
  • columnIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

cellcontextmenu

public event cellcontextmenu
Fires when a cell is right clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • rowIndex : Number
  • cellIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

celldblclick

public event celldblclick
Fires when a cell is double clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • rowIndex : Number
  • columnIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

click

public event click
The raw click event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

columnmove

public event columnmove
Fires when the user moves a column
Subscribers will be called with the following parameters:
  • oldIndex : Number
  • newIndex : Number
This event is defined by Grid.

columnresize

public event columnresize
Fires when the user resizes a column
Subscribers will be called with the following parameters:
  • columnIndex : Number
  • newSize : Number
This event is defined by Grid.

contextmenu

public event contextmenu
The raw contextmenu event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

dblclick

public event dblclick
The raw dblclick event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

dragdrop

public event dragdrop
Fires when dragged row(s) are dropped on a valid DD target
Subscribers will be called with the following parameters:
  • this : Grid
  • dd : Ext.GridDD
    The drag drop object
  • targetId : String
    The target drag drop object
  • e : event
    The raw browser event
This event is defined by Grid.

dragenter

public event dragenter
Fires when the dragged row(s) first cross another DD target while being dragged
Subscribers will be called with the following parameters:
  • this : Grid
  • dd : Ext.GridDD
    The drag drop object
  • targetId : String
    The target drag drop object
  • e : event
    The raw browser event
This event is defined by Grid.

dragout

public event dragout
Fires when the dragged row(s) leave another DD target while being dragged
Subscribers will be called with the following parameters:
  • this : Grid
  • dd : Ext.GridDD
    The drag drop object
  • targetId : String
    The target drag drop object
  • e : event
    The raw browser event
This event is defined by Grid.

dragover

public event dragover
Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
Subscribers will be called with the following parameters:
  • this : Grid
  • dd : Ext.GridDD
    The drag drop object
  • targetId : String
    The target drag drop object
  • e : event
    The raw browser event
This event is defined by Grid.

enddrag

public event enddrag
Fires when a drag operation is complete
Subscribers will be called with the following parameters:
  • this : Grid
  • dd : Ext.GridDD
    The drag drop object
  • e : event
    The raw browser event
This event is defined by Grid.

headerclick

public event headerclick
Fires when a header is clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • columnIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

headercontextmenu

public event headercontextmenu
Fires when a header is right clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • columnIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

headerdblclick

public event headerdblclick
Fires when a header cell is double clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • rowIndex : Number
  • columnIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

keydown

public event keydown
The raw keydown event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

keypress

public event keypress
The raw keypress event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

mousedown

public event mousedown
The raw mousedown event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

mouseout

public event mouseout
The raw mouseout event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

mouseover

public event mouseover
The raw mouseover event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

mouseup

public event mouseup
The raw mouseup event for the entire grid.
Subscribers will be called with the following parameters:
  • e : Ext.EventObject
This event is defined by Grid.

rowclick

public event rowclick
Fires when a row is clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • rowIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

rowcontextmenu

public event rowcontextmenu
Fires when a row is right clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • rowIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

rowdblclick

public event rowdblclick
Fires when a row is double clicked
Subscribers will be called with the following parameters:
  • this : Grid
  • rowIndex : Number
  • e : Ext.EventObject
This event is defined by Grid.

startdrag

public event startdrag
Fires when row(s) start being dragged
Subscribers will be called with the following parameters:
  • this : Grid
  • dd : Ext.GridDD
    The drag drop object
  • e : event
    The raw browser event
This event is defined by Grid.

Config Details

A

A : Object
javascript RegExp defining tagNames allowed to have text selection (Defaults to /INPUT|TEXTAREA|SELECT/i).
This config option is defined by Grid.

An

An : Object
Ext.LoadMask config or true to mask the grid while loading (defaults to false).
This config option is defined by Grid.

If

If : Boolean
autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of rows measured to get a columns size - defaults to 0 (all rows).
This config option is defined by Grid.

The

The : Object
Ext.grid.GridView used by the grid. This can be set before a call to render().
This config option is defined by Grid.

True

True : Boolean
to fit the height of the grid container to the height of the data. Defaults to false.
This config option is defined by Grid.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.