
Public Member Functions | |
| String | afterUpdate () |
| AjaxGrid (WOContext context) | |
| void | appendToResponse (WOResponse response, WOContext context) |
| boolean | canReorder () |
| boolean | canResort () |
| boolean | checkHashCodes () |
| String | columnComponentName () |
| Format | columnFormatter () |
| void | columnOrderUpdated () |
| NSMutableDictionary | columnsByKeypath () |
| Object | columnValue () |
| NSMutableDictionary | configurationData () |
| void | containerUpdated () |
| NSDictionary | currentColumn () |
| String | currentColumnID () |
| int | currentColumnSortIndex () |
| NSMutableDictionary | currentColumnSortOrder () |
| String | currentKeyPath () |
| String | currentSortPath () |
| WODisplayGroup | displayGroup () |
| String | dragHeaderOnly () |
| String | enableDragAndDrop () |
| NSMutableDictionary | formattersByKeypath () |
| boolean | hasMandatorySort () |
| String | initScript () |
| boolean | isCurrentColumnSorted () |
| boolean | isCurrentColumnSortedAscending () |
| boolean | isRowSelected () |
| NSDictionary | manadatorySortDictionary () |
| String | manadatorySortKeyPath () |
| void | removeSorting () |
| String | removeSortingID () |
| NSKeyValueCodingAdditions | row () |
| String | rowClass () |
| String | rowID () |
| String | rowIdentifier () |
| String | rowIdentifierKey () |
| int | rowIndex () |
| String | rowStyle () |
| NSMutableArray | selectedObjects () |
| void | setColumnValue (Object value) |
| void | setCurrentColumn (NSDictionary newColumn) |
| void | setRow (NSKeyValueCodingAdditions newRow) |
| void | setRowIndex (int index) |
| boolean | showRowSelector () |
| NSMutableDictionary | sortOrdersByKeypath () |
| void | sortOrderUpdated () |
| boolean | synchronizesVariablesWithBindings () |
| String | tableID () |
| AjaxGrid | thisComponent () |
| void | toggleRowSelection () |
| String | toggleRowSelectionID () |
Static Public Member Functions | |
| static void | updateBatchSize (WODisplayGroup dg, int batchSize) |
| static void | updateDisplayGroupSort (WODisplayGroup dg, NSArray sortConfig) |
Static Public Attributes | |
| static final String | AFTER_UPDATE_BINDING = "afterUpdate" |
| static final String | BATCH_SIZE = "batchSize" |
| static final String | CAN_REORDER = "canReorder" |
| static final String | CAN_RESORT = "canResort" |
| static final String | CHECK_HASH_CODES = "er.extensions.ERXWORepetition.checkHashCodes" |
| static final String | COLUMNS = "columns" |
| static final String | COMPONENT_NAME = "component" |
| static final String | CONFIGURATION_DATA_BINDING = "configurationData" |
| static final String | CONFIGURATION_UPDATED = "configurationUpdated" |
| static final String | DESTINATION_COLUMN_FORM_VALUE = "destinationColumn" |
| static final String | DISPLAY_GROUP_BINDING = "displayGroup" |
| static final String | DRAG_HEADER_ONLY = "dragHeaderOnly" |
| static final String | EVEN_ROW_CSS_CLASS = "evenRowCSSClass" |
| static final String | EVEN_ROW_CSS_STYLE = "evenRowCSSStyle" |
| static final String | FORMAT_PATTERN = "formatPattern" |
| static final String | FORMATTER_CLASS = "formatterClass" |
| static final String | KEY_PATH = "keyPath" |
| static final String | MANDATORY_SORT = "mandatorySort" |
| static final String | MANDATORY_SORT_ORDER_FLAG = "isMandatorySortOrder" |
| static final String | ODD_ROW_CSS_CLASS = "oddRowCSSClass" |
| static final String | ODD_ROW_CSS_STYLE = "oddRowCSSStyle" |
| static final String | ROW_IDENTIFIER = "rowIdentifier" |
| static final String | SELECTED_OBJECTS_BINDING = "selectedObjects" |
| static final String | SELECTED_ROW_CSS_CLASS = "selectedRowCSSClass" |
| static final String | SELECTED_ROW_CSS_STYLE = "selectedRowCSSStyle" |
| static final String | SHOW_ROW_SELECTOR = "showRowSelector" |
| static final String | SORT_ASCENDING = "ascending" |
| static final String | SORT_DESCENDING = "descending" |
| static final String | SORT_DIRECTION = "direction" |
| static final String | SORT_ORDER = "sortOrder" |
| static final String | SORT_PATH = "sortPath" |
| static final String | SOURCE_COLUMN_FORM_VALUE = "sourceColumn" |
| static final String | TABLE_ID = "tableID" |
| static final String | TITLE = "title" |
| static final String | UNSELECTED_ROW_CSS_CLASS = "unselectedRowCSSClass" |
| static final String | UNSELECTED_ROW_CSS_STYLE = "unselectedRowCSSStyle" |
| static final String | UPDATE_CONTAINER_ID = "updateContainerID" |
| static final String | UPDATE_FREQUENCY = "updateFrequency" |
| static final String | WILL_UPDATE_BINDING = "willUpdate" |
Protected Member Functions | |
| int | batchSize () |
| void | clearCachedConfiguration () |
| NSMutableArray | columns () |
| NSMutableArray | sortOrders () |
| void | updateBatchSize () |
| void | updateDisplayGroupSort () |
Private Attributes | |
| NSMutableDictionary | columnsByKeypath |
| NSDictionary | currentColumn |
| WODisplayGroup | displayGroup |
| NSMutableDictionary | formattersByKeypath |
| NSKeyValueCodingAdditions | row |
| int | rowIndex |
| NSMutableArray | selectedObjects |
| Boolean | showRowSelector |
| NSMutableDictionary | sortOrdersByKeypath |
The data is taken from a WODisplayGroup. Use er.extensions.ERXBatchingDisplayGroup to provide high performance access to large data sets.
Navigation between batches is not implemented as implementing in it another component bound to the display group will allow for a more flexible UI.
Configuration is provided by an NSMutableDictionary and NSMutableArray data structure. This reduces the number of bindings, eases keeping related lists of information in synch, and provides an easy path for serializing a user's customizations to configuration for persistent storage. Described as a plist, the format of the configuration information is:
{
tableID = "exampleAjaxGrid"; // Goes on main table tag
updateContainerID = "ajaxGridContainer"; // Goes on div wrapping table, used with AjaxUpdate* components
updateFrequency = 60; // Optional frequency of automatic updates of the grid contents
// This function uses the Ajax.PeriodicalUpdater which does an
// update when it is first created, rather than waiting for the
// frequency time before making the first request
cssClass = "ajaxGrid"; // CSS class attribute on main table tag, optional
cssStyle = "border: thin solid #000000;"; // CSS style attribute on main table tag, optional
evenRowCSSClass = "yellowBackground"; // CSS class attribute on even rows, optional
oddRowCSSClass = "greyBackground"; // CSS class attribute on odd rows, optional
evenRowCSSStyle = "background:lightyellow;" // CSS style attribute on even rows, optional
oddRowCSSStyle = "background:lightgrey;"; // CSS style attribute on odd rows, optional
showRowSelector = true; // Optional, defaults to true, if false no UI is shown to select a row - the cell has only
selectedRowCSSClass = "yellowBackground"; // Secondary CSS class attribute on selected rows, optional
unselectedRowCSSClass = "greyBackground"; // Secondary CSS class attribute on unselected rows, optional
selectedRowCSSStyle = "background:lightyellow;"; // Secondary CSS style attribute on selected rows, optional
unselectedRowCSSStyle = "background:lightgrey;";// Secondary CSS style attribute on unselected rows, optional
canReorder = true; // Optional, defaults to true, Enables (or disables) drag and drop reordering of columns
canResort = true; // Optional, defaults to true, Enables (or disables) sorting by clicking the column titles
dragHeaderOnly = true; // Optional, defaults to false, true if only the title/header cells can
// be dragged to re-order columns
batchSize = 10; // Controls size of batch in display group, use zero for no batching
rowIdentifier = adKey; // Optional, key path into row returning a unique identifier for the row
// rowIdentifier is used to build HTML ID attributes, so a String or Number works best
er.extensions.ERXWORepetition.checkHashCodes = true; // Optional override for global ERXWORepetition setting
columns = ( // List of columns to display, controls the initial display order
{
title = "Name"; // Title for this column in the table header row
keyPath = "fullName"; // Key path into row returning the data to display in this colunmn
}, // keyPath is optional if component is specified
{
title = "Department";
keyPath = "department.name";
sortPath = "department.code"; // sortPath is an optional path to sort this column on, defaults to keyPath
// This is useful if keyPath points to something that can't be sorted or a
// different sort order is need, e.g. here by Department Code rather than name.
// It can also be used when component is used to provide a sorting for the column
},
{
title = "Hire Date";
keyPath = "hireDate";
formatterClass = "com.webobjects.foundation.NSTimestampFormatter"; // Class of formatter to apply to values in this column
formatPattern = "m/d/y"; // Optional pattern if needed by formatter
},
{
title = "Salary";
keyPath = "salary";
formatterClass = "com.webobjects.foundation.NSNumberFormatter";
formatPattern = "$###,##0.00";
cssClass = "alignRight"; // CSS class attribute td tag in this column, optional
},
{
title = "Vacation Days";
keyPath = "daysVacation";
formatterClass = "com.webobjects.foundation.NSNumberFormatter";
cssStyle = "text-align: right;"; // CSS style attribute td tag in this column, useful for text-align and width, optional
},
{
title = "Actions";
keyPath = ""; // Missing or empty keypath results in the current object itself being passed to component
component = "EmployeeActions"; // Name of WOComponent to be displayed in this column. Gets passed two bindings: value (Object),
// and grid (AjaxGrid) so that any other needed data can be accessed
cssClass = "alignCenter";
}
);
sortOrder = (
{
keyPath = "department.code"; // If the related column definition uses sortPath, this keyPath should match it
// This was left as keyPath (rather than sortPath) for backwards compatibility
direction = "ascending";
},
{
keyPath = "salary";
direction = "descending";
},
{
keyPath = "daysVacation";
direction = "ascending";
}
); // This sort is always present so that if the grid is sorted with some ordering where
mandatorySort = { // identical values span multiple batches, batch membership will not be indeterminate.
keyPath = "masterAdKey"; // This will only function if this sorting is quite unique (e.g. like a PK).
direction = "ascending"; // If this sort is also present in sortOrder (above), it will not be duplicated
}; // but will still always be present. If the user has not manually selected it,
// it will not be indicated in the UI.
}
You can get the configuration information from a plist file with code like this:
public NSMutableDictionary configData() {
if (configData == null) {
// Get data from user preferences here if available, otherwise load the defaults
configData = mySession().user().preferencesFor("AjaxGridExample");
if (configData == null) {
NSData data = new NSData(application().resourceManager().bytesForResourceNamed("AjaxGridExampleConfiguration.plist", null, NSArray.EmptyArray));
configData = new NSMutableDictionary((NSDictionary) NSPropertyListSerialization.propertyListFromData(data, "UTF-8"));
}
}
return configData; }
When the grid contents are updated the AjaxUpdateContainer needs to be updated. The grid configuration updateContainerID gives the ID for this. This can be used as the updateContainerID in a AjaxUpdateLink or <updateContainerID>Update() can be called directly. This results in a call to ajaxGrid_init('<tableID>'); to be re-enable drag and drop on the table.
Here is an example. In this example, updateContainerID is used to update the grid, and then the NavBar container is updated manually from onComplete. The reason for this is that the grid needs to update first so that the correct values are available for updating the NavBar.
Relevant Configuration:
{
tableID = "exampleAjaxGrid";
updateContainerID = "ajaxGridContainer";
. . .
WOD Bindings:
NavUpdater: AjaxUpdateContainer { id = "NavBar"; }
NextBatch : AjaxUpdateLink { action = nextBatch; updateContainerID = "ajaxGridContainer"; onComplete = "function(request) { NavBarUpdate(); }"; }
In addition to the classes defined in the grid configuration, AjaxGrid uses some set class names:
| Class Name | Used For |
|---|---|
| ajaxGridRemoveSorting | The th of cell containing link to remove all sorting |
| ajaxGridColumnTitle | The th of cells containing column titles |
| ajaxGridSortAscending | The span that wraps index and direction indicator of columns sorted in ascending order |
| ajaxGridSortDescending | The span that wraps index and direction indicator of columns sorted in descending order |
| ajaxGridSelectRow | The td of cells containing the row selection link </table Advanced Styling of the Grid
The grid contains several places were there are nested anonymous
<th class="ajaxGridRemoveSorting"><span>X</span><em> </em></th> The default X can replaced with an image with this CSS:
th.ajaxGridRemoveSorting a span {display: none;}
th.ajaxGridRemoveSorting a em {
background-image: url(http://vancouver.global-village.net/WebObjects/Frameworks/JavaDirectToWeb.framework/WebServerResources/trashcan-btn.gif);
background-repeat:no-repeat;
padding-right: 12px;
padding-bottom: 5px;
}
You can also use
Updating the ConfigurationIf you update the configuration after the grid has been displayed, some items will not update as the information is cached. Add a value under the key AjaxGrid.CONFIGURATION_UPDATED to notify the grid to discard the cached information. The grid will remove the value under this key after it has cleared the cache. To Do
displayGroup required, WODisplayGroup acting as source and batching engine for the data to be displayed configurationData required, NSMutableDictionary used to configure grid, see documentation for details selectedObjects optional, NSMutableArray list of rows that the user has selected from the grid willUpdate optional, Ajax action method called when the AjaxUpdateContainer is being updated, but before it renders its content afterUpdate optional, JavaScript to execute client-side after the grid has updated updateContainerParameters optional, passed as parameters binding to the AjaxUpdateContainer wrapping the grid
|
| AjaxGrid | ( | WOContext | context | ) |
| String afterUpdate | ( | ) |
Binding value for onRefreshComplete function of AjaxUpdate container. Returns the value from the AFTER_UPDATE_BINDING followed by enableDragAndDrop().
| void appendToResponse | ( | WOResponse | response, | |
| WOContext | context | |||
| ) |
Adds movecolumns.js to the header.
| int batchSize | ( | ) | [protected] |
| boolean canReorder | ( | ) |
Returns CAN_REORDER value from configurationData(), or true if not configured.
true if column re-ordering is enabled | boolean canResort | ( | ) |
Returns CAN_RESORT value from configurationData(), or true if not configured.
true if data sorting is enabled | boolean checkHashCodes | ( | ) |
Allows configuration data to override ERXWORepetition default for checkHashCodes.
| void clearCachedConfiguration | ( | ) | [protected] |
Clears local cache of configuration data so that fresh data will be cached.
| String columnComponentName | ( | ) |
| Format columnFormatter | ( | ) |
| void columnOrderUpdated | ( | ) |
Ajax action method for when columns are dragged and dropped. Updates configurationData().
| NSMutableArray columns | ( | ) | [protected] |
Returns COLUMNS value from configurationData()
| Object columnValue | ( | ) |
| NSMutableDictionary configurationData | ( | ) |
| void containerUpdated | ( | ) |
This method is called when the AjaxUpdateContainer is about to update. It invokes the willUpdate action binding, if set, and discards the result.
| NSDictionary currentColumn | ( | ) |
Cover method for item binding of a WORepetition.
| String currentColumnID | ( | ) |
| int currentColumnSortIndex | ( | ) |
| NSMutableDictionary currentColumnSortOrder | ( | ) |
| String currentKeyPath | ( | ) |
| String currentSortPath | ( | ) |
| WODisplayGroup displayGroup | ( | ) |
| String dragHeaderOnly | ( | ) |
| String enableDragAndDrop | ( | ) |
Returns Javacript to (re)initialize drag and drop on the grid.
| boolean hasMandatorySort | ( | ) |
true if the configuration has anything under the MANDATORY_SORT key | String initScript | ( | ) |
Script that goes on this page to initialize drag and drop on the grid when the page loads / re-loads
| boolean isCurrentColumnSorted | ( | ) |
true if currentColumn() is part of the sort ordering but is not the mandatory sort | boolean isCurrentColumnSortedAscending | ( | ) |
true if currentColumn() is part of the sort ordering and is being sorted in ascending order | boolean isRowSelected | ( | ) |
true if row() is in selectedObjects() | NSDictionary manadatorySortDictionary | ( | ) |
Returns a copy of the mandatory sort configuration with an additional (dummy) value for the MANDATORY_SORT_ORDER_FLAG.
| String manadatorySortKeyPath | ( | ) |
| void removeSorting | ( | ) |
Ajax action method for when control clicked to remove all sorting. Updates configurationData() and displayGroup().
| String removeSortingID | ( | ) |
| NSKeyValueCodingAdditions row | ( | ) |
Cover method for item binding of a WORepetition.
| String rowClass | ( | ) |
Returns EVEN_ROW_CSS_CLASS or ODD_ROW_CSS_CLASS, depending on rowIndex(), value from configurationData() followed by SELECTED_ROW_CSS_CLASS or UNSELECTED_ROW_CSS_CLASS, depending on isRowSelected(), value from configurationData()
| String rowID | ( | ) |
Returns a value suitable for use as part of an HTML ID attribute that uniquely identifies this row. If rowIdentifier() is set, used row().valueForKeyPath(rowIdentifier()), otherwise uses "row_" and the index of the row in the list of objects.
| String rowIdentifier | ( | ) |
Returns an optional key path into row that will return a value that uniquely identifies this row. This should be suitable for use as part of an HTML ID attribute.
| String rowIdentifierKey | ( | ) |
Returns a key into this row that produces a unique value for this row.
| int rowIndex | ( | ) |
Cover method for index binding of a WORepetition.
| String rowStyle | ( | ) |
Returns EVEN_ROW_CSS_STYLE or ODD_ROW_CSS_STYLE, depending on rowIndex(), value from configurationData() folowed by SELECTED_ROW_CSS_STYLE or UNSELECTED_ROW_CSS_STYLE, depending on isRowSelected(), value from configurationData()
This list is implemented by AjaxGrid and is not based on the display group's selected objects. The list of selected objects is maintained across all batches.
| void setColumnValue | ( | Object | value | ) |
Method used with automatic synchronizing custom components.
| value | new value for row() in this column |
| void setCurrentColumn | ( | NSDictionary | newColumn | ) |
Cover method for item binding of a WORepetition.
| newColumn | current column being rendered |
| void setRow | ( | NSKeyValueCodingAdditions | newRow | ) |
Cover method for item binding of a WORepetition.
| newRow | current row being rendered |
| void setRowIndex | ( | int | index | ) |
Cover method for index binding of a WORepetition.
| index | inded of current row being rendered |
| boolean showRowSelector | ( | ) |
true if unset | NSMutableArray sortOrders | ( | ) | [protected] |
Returns SORT_ORDER value from configurationData()
| void sortOrderUpdated | ( | ) |
Ajax action method for when column titles are clicked to change sorting. Updates configurationData() and displayGroup().
| boolean synchronizesVariablesWithBindings | ( | ) |
| String tableID | ( | ) |
| AjaxGrid thisComponent | ( | ) |
| void toggleRowSelection | ( | ) |
Toggles inclusion of row into selectedObjects() (i.e. selects and de-selects it).
| String toggleRowSelectionID | ( | ) |
| void updateBatchSize | ( | ) | [protected] |
Updates numberOfObjectsPerBatch on the display group
| static void updateBatchSize | ( | WODisplayGroup | dg, | |
| int | batchSize | |||
| ) | [static] |
Updates numberOfObjectsPerBatch on the display group. This is public and static so that a display group can be pre-configured for the AjaxGrid to avoid re-fetching (happens if there is a nav bar that gets rendered before the grid).
| dg | the WODisplayGroup to set the sortOrderings of | |
| batchSize | batch size from grid configuration (not EOSortOrderings) |
| void updateDisplayGroupSort | ( | ) | [protected] |
Updates sort orders on the display group.
| static void updateDisplayGroupSort | ( | WODisplayGroup | dg, | |
| NSArray | sortConfig | |||
| ) | [static] |
Updates sort orders on the display group. This is public and static so that a display group can be pre-configured for the AjaxGrid to avoid re-fetching (happens if there is a nav bar that gets rendered before the grid).
| dg | the WODisplayGroup to set the sortOrderings of | |
| sortConfig | NSArray of sorts from grid configuration (not EOSortOrderings) |
final String AFTER_UPDATE_BINDING = "afterUpdate" [static] |
final String BATCH_SIZE = "batchSize" [static] |
final String CAN_REORDER = "canReorder" [static] |
final String CAN_RESORT = "canResort" [static] |
final String CHECK_HASH_CODES = "er.extensions.ERXWORepetition.checkHashCodes" [static] |
NSMutableDictionary columnsByKeypath [private] |
final String COMPONENT_NAME = "component" [static] |
final String CONFIGURATION_DATA_BINDING = "configurationData" [static] |
final String CONFIGURATION_UPDATED = "configurationUpdated" [static] |
NSDictionary currentColumn [private] |
final String DESTINATION_COLUMN_FORM_VALUE = "destinationColumn" [static] |
final String DISPLAY_GROUP_BINDING = "displayGroup" [static] |
WODisplayGroup displayGroup [private] |
final String DRAG_HEADER_ONLY = "dragHeaderOnly" [static] |
final String EVEN_ROW_CSS_CLASS = "evenRowCSSClass" [static] |
final String EVEN_ROW_CSS_STYLE = "evenRowCSSStyle" [static] |
final String FORMAT_PATTERN = "formatPattern" [static] |
final String FORMATTER_CLASS = "formatterClass" [static] |
NSMutableDictionary formattersByKeypath [private] |
final String MANDATORY_SORT = "mandatorySort" [static] |
final String MANDATORY_SORT_ORDER_FLAG = "isMandatorySortOrder" [static] |
final String ODD_ROW_CSS_CLASS = "oddRowCSSClass" [static] |
final String ODD_ROW_CSS_STYLE = "oddRowCSSStyle" [static] |
NSKeyValueCodingAdditions row [private] |
final String ROW_IDENTIFIER = "rowIdentifier" [static] |
int rowIndex [private] |
final String SELECTED_OBJECTS_BINDING = "selectedObjects" [static] |
final String SELECTED_ROW_CSS_CLASS = "selectedRowCSSClass" [static] |
final String SELECTED_ROW_CSS_STYLE = "selectedRowCSSStyle" [static] |
NSMutableArray selectedObjects [private] |
final String SHOW_ROW_SELECTOR = "showRowSelector" [static] |
Boolean showRowSelector [private] |
final String SORT_ASCENDING = "ascending" [static] |
final String SORT_DESCENDING = "descending" [static] |
final String SORT_DIRECTION = "direction" [static] |
final String SORT_ORDER = "sortOrder" [static] |
NSMutableDictionary sortOrdersByKeypath [private] |
final String SOURCE_COLUMN_FORM_VALUE = "sourceColumn" [static] |
final String UNSELECTED_ROW_CSS_CLASS = "unselectedRowCSSClass" [static] |
final String UNSELECTED_ROW_CSS_STYLE = "unselectedRowCSSStyle" [static] |
final String UPDATE_CONTAINER_ID = "updateContainerID" [static] |
final String UPDATE_FREQUENCY = "updateFrequency" [static] |
final String WILL_UPDATE_BINDING = "willUpdate" [static] |
1.5.8