Yahoo! UI Library

DataTable  1.0.0

Yahoo! UI Library > DataTable > YAHOO.widget.QuickEditDataTable
Search:
 
Filters

Class YAHOO.widget.QuickEditDataTable - extends YAHOO.widget.DataTable

The QuickEditDataTable class extends the DataTable class to provide QuickEdit mode. (It could just as easily extend ScrollingDataTable.) QuickEdit mode allows the user to edit all the values that are visible in the table, controlled by the column configuration. Each editable cell contains an input field. If the user decides to save the changes, then you can extract the changes by calling getQuickEditChanges().

For a column to be editable in QuickEdit mode, the column configuration must include quickEdit. The contents of this object define the column's behavior in QuickEdit mode.

If a column should not be editable, but needs to be formatted differently in QuickEdit mode, then you must define qeFormatter in the column configuration. This is simply a normal cell formatter function that will be used in QuickEdit mode. The static functions readonly*QuickEditFormatter provide examples.

The following configuration can be provided as part of quickEdit:

copyDown
If true, the top cell in the column will have a button to copy the value down to the rest of the rows.
formatter
The cell formatter which will render an appropriate form field: <input type="text">, <textarea>, or <select>.
validation
Validation configuration for every field in the column.

The following configuration can be provided as part of quickEdit.validation:

css
CSS classes encoding basic validation rules:
yiv-required
Value must not be empty.
yiv-length:[x,y]
String must be at least x characters and at most y characters. At least one of x and y must be specified.
yiv-integer:[x,y]
The integer value must be at least x and at most y. x and y are both optional.
yiv-decimal:[x,y]
The decimal value must be at least x and at most y. Exponents are not allowed. x and y are both optional.
fn
A function that will be called with the DataTable as its scope and the cell's form element as the argument. Return true if the value is valid. Otherwise, call this.displayQuickEditMessage(...) to display an error and return false.
msg
A map of types to messages that will be displayed when a basic or regex validation rule fails. The valid types are: required, min_length, max_length, integer, decimal, and regex. There is no default for type regex, so you must specify a message if you configure a regex validation.
regex
Regular expression that the value must satisfy in order to be considered valid.

Custom QuickEdit Formatters

To write a custom cell formatter for QuickEdit mode, you must structure the function as follows:

function myQuickEditFormatter(el, oRecord, oColumn, oData) {
  var markup =
    '<input type="text" class="{yiv} yui-quick-edit yui-quick-edit-key:{key}"/>' +
    YAHOO.widget.QuickEditDataTable.MARKUP_QE_ERROR_DISPLAY;
    el.innerHTML = lang.substitute(markup, {
      key: oColumn.key,
      yiv: oColumn.quickEdit.validation ? (oColumn.quickEdit.validation.css || '') : ''
    });
    el.firstChild.value = extractMyEditableValue(oData);
    YAHOO.widget.QuickEditDataTable.copyDownFormatter.apply(this, arguments);
};

You can use textarea or select instead of input, but you can only create a single field.

extractMyEditableValue does not have to be a separate function nor must it be limited to using only oData. The work should normally be done inline in the formatter function, but the name of the sample function makes the point clear.

Constructor

YAHOO.widget.QuickEditDataTable ( elContainer , aColumnDefs , oDataSource , oConfigs )
Parameters:
elContainer <HTMLElement> Container element for the TABLE.
aColumnDefs <Object[]> Array of object literal Column definitions.
oDataSource <YAHOO.util.DataSource> DataSource instance.
oConfigs <object> (optional) Object literal of configuration values.

Methods

cancelQuickEdit

void cancelQuickEdit ( )
Switch out of QuickEdit mode. THIS DISCARDS ALL DATA! If you want to save the data, call getQuickEditChanges() BEFORE calling this function.

clearQuickEditMessages

void clearQuickEditMessages ( )
Clear all validation messages in QuickEdit mode.

copyDownFormatter

static void copyDownFormatter ( )
Called with exactly the same arguments as a normal cell formatter, this function inserts a "Copy down" button if the cell is in the first row of the DataTable. Call this at the end of your QuickEdit formatter.

displayQuickEditMessage

void displayQuickEditMessage ( e , msg , type , scroll )
Display a message for a QuickEdit field. If an existing message with a higher precedence is already visible, it will not be replaced.
Parameters:
e <Element> form field
msg <String> message to display
type <String> message type: error, warn, success, info
scroll <boolean> If false, does not scroll, even if this is the first message to display.

getQuickEditChanges

mixed getQuickEditChanges ( )
Return the changed values. For each row, an object is created with only the changed values. The object keys are the column keys. If you need values from particular columns to be included always, even if the value did not change, include the key "quickEditChangesAlwaysInclude" in the DataTable configuration and pass an array of column keys.
Returns: mixed
array if all validation passed, false otherwise

readonlyLinkQuickEditFormatter

static void readonlyLinkQuickEditFormatter ( )
Called with exactly the same arguments as any other cell formatter, this function displays an email address without the anchor tag. Use this as the column's qeFormatter if the column should not be editable in QuickEdit mode.

startQuickEdit

void startQuickEdit ( )
Switch to QuickEdit mode. Columns that have quickEdit defined will be editable.

textareaQuickEditFormatter

static void textareaQuickEditFormatter ( )
Called with exactly the same arguments as any other cell formatter, this function displays a textarea field.

textQuickEditFormatter

static void textQuickEditFormatter ( )
Called with exactly the same arguments as any other cell formatter, this function displays an input field.

validateQuickEdit

boolean validateQuickEdit ( )
Validate the QuickEdit data.
Returns: boolean
true if all validation checks pass

Events

beforeQuickEditChangesAlwaysIncludeChange

beforeQuickEditChangesAlwaysIncludeChange ( event )
Fires before the value for the configuration attribute 'quickEditChangesAlwaysInclude' changes. Return false to cancel the attribute change.
Parameters:
event <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

quickEditChangesAlwaysIncludeChange

quickEditChangesAlwaysIncludeChange ( event )
Fires when the value for the configuration attribute 'quickEditChangesAlwaysInclude' changes.
Parameters:
event <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

Configuration Attributes

quickEditChangesAlwaysInclude - {Array}

Record keys to always include in result from getQuickEditChanges().
Default Value: []

YAHOO.widget.QuickEditDataTable.status_order - static {Array}

Names of supported status values, highest precedence first. Default: [ 'error', 'warn', 'success', 'info' ]

This is static because it links to CSS rules that define the appearance of each status type: .formmgr-has{status}


YAHOO.widget.QuickEditDataTable.Strings - static {Object}

Map of localizable strings used by pre-validation.

required_string
Displayed when yiv-required fails on an input field.
required_menu
Displayed when yiv-required fails on a select element.
length_too_short, length_too_long, length_out_of_range
Displayed when yiv-length fails on an input field.
integer, integer_too_small, integer_too_large, integer_out_of_range
Displayed when yiv-integer fails on an input field.
decimal, decimal_too_small, decimal_too_large, decimal_out_of_range
Displayed when yiv-decimal fails on an input field.


Copyright © 2011 Yahoo! Inc. All rights reserved.