4D Ajax Framework v11 Datagrid (All About)
4D Ajax Framework v11 Datagrid (All About)
The software described in this manual is governed by the grant of license provided in this package. The soft-
ware and the manual are copyrighted and may not be reproduced in whole or in part except for the personal
licensee’s use and solely in accordance with the contractual terms. This includes copying the electronic
media, archiving, or using the software in any manner other than that provided for in the Software license
Agreement.
4D, 4D Draw, 4D Write, 4D View, 4D Insider, 4D, 4D Server and the 4th Dimension and 4D logos are regis-
tered trademarks of 4D SAS.
Microsoft, Windows and Windows NT are registered trademarks of Microsoft Corporation.
Apple, Macintosh, Mac OS and QuickTime are trademarks or registered trademarks of Apple Computer Inc.
Mac2Win Software Copyright © 1990-2008 is a product of Altura Software, Inc.
ACROBAT © Copyright 1987-2008, Secret Commercial Adobe Systems Inc. All rights reserved. ACROBAT is a
registered trademark of Adobe Systems Inc.
This product includes software developed by the Apache Software Foundation (http://www.apache.org/).
4D includes cryptographic software written by Eric Young ([email protected])
4D includes software written by Tim Hudson ([email protected]).
Spellchecker © Copyright SYNAPSE Développement, Toulouse, France, 1994-2005.
All other referenced trade names are trademarks, registered trademarks, or copyrights of their respective
holders.
Contents
Chapter 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
New Query, Add Query, and Run Query . . . . . . . . . . . . . . . . . . 26
Send custom values to 4D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Get custom values from 4D . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Query all records. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Max number of characters per field . . . . . . . . . . . . . . . . . . . . . . 29
Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
On Before and On After Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Before data display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Check values before display . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Modify values before display . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Get number of returned records. . . . . . . . . . . . . . . . . . . . . . . . . 31
Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Select row by record id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Select row by number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Add, remove, and clear. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Delete selection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Selection Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Drag & drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Set cells as drop zone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Set cell as draggable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Set draggable object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Status bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Show message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Preset queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Sidebar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Preset queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
New record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Edit record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Allow editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Inline editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Allow inline editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Initiate inline editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Save edited record. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Cancel inline editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
On cell, row, column click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
On data load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Before and After Hover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
CSS Styling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Override Styling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Set entire grid class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Assign classes to Rows, Columns, and Cells . . . . . . . . . . . . . . . 49
Select single records, multiple records at the same time, or none at all.
Fire events when rows or cells are selected, and when data arrives from
the back end.
Apply CSS styling.
And more…
Create a new Data First, create the Data Grid using the following:
Grid var myGrid = new dax_dataGrid(selection, location,
headerRows, lockedLeftColumns, useControlColumn);
selection - Name of Table, View, or DCS the Data Grid will display.
location - Name of the <div> on the HTML page where the Data
Grid will be embedded. Pass null or no value to float the Data Grid
as a window.
headerRows - (optional) Number of rows the header is by height.
Default size is 1 row. The first header row automatically has the
capability of being populated by titles. Additional header rows are
blank and are up to the Developer to populate.
lockedLeftColumns - (optional) Number of columns to lock on the
left side.
useControlColumn - (optional) Show control column on the left.
Default value is 'True'. Used for inline editing.
Initialize the Data Then after creating the grid, use the .go() call to run and display it.
Grid myGrid.go();
At this point, a Data Grid will appear on your HTML page. The new
dax_dataGrid and the .go() commands are the minimum commands
necessary for displaying a Data Grid.
Note var myGrid = new dax_dataGrid('People'); also displays the Data Grid as
a floating window.
Add footers The following command can be used to set the number of footer rows.
myGrid.setFooterRows(number of footer rows);
Note It is recommended to call this command before the .go() command.
` This example will build a Data Grid as a floating window with 2 footer
rows.
var myGrid = new dax_dataGrid('People', null);
// Add two footer rows
myGrid.setFooterRows(2);
myGrid.go();
Lock right columns The following command can be used to lock the number of right
columns.
myGrid.setRightLockedColumns(number of locked right
columns);
Note It is recommended to call this command before the .go() command.
Resizing <div> areas on an HTML page may resize. If that resized <div> contains
your Data Grid, you will need to resize the Data Grid so that it fits
appropriately. Call the following command so that the Data Grid is
correctly resized.
myGrid.activate();
The Data Grid will resize to fit in the <div> that contains it.
` In this example, first the <div> that holds the grid is resized to 600
pixels wide. Then, the .activate() command is called to resize the Data
Grid into the <div>.
// Change the size of the div that holds the Data Grid
$('myGridDiv').style.width = '600px';
// Update Data Grid to fit
myGrid.activate();
Picture Preview
Every picture field in the Data Grid displays a 'View Image' link to load
it. When users mouse over this link a preview of the image appears.
Use the following command to turn Picture Preview on or off.
myGrid.enablePicturePreview(previewEnabled)
previewEnabled - Boolean. Set to true to enable Picture Preview. Set
to false otherwise. Picture Preview is set to true by default.
Data
Auto refresh Enable or disable the Auto Refresh feature using the commands below.
myGrid.enableAutoRefresh();
myGrid.disableAutoRefresh();
Auto Refresh is on by default. With Auto Refresh on, its default interval
is 3 minutes (180 seconds). Modify the refresh rate using the command
below.
myGrid.setRefreshInterval(seconds);
` In this example the Data Grid is set to refresh every 10 minutes (600
seconds).
// refresh grid every 10 minutes
myGrid.setRefreshInterval(600);
Set and get cell To get the contents of a cell use this command:
contents var cellValue = myGrid.getCellValue (row, col);
row - Specify the row of the cell in which you intend to get the
value from.
col - Specify the column of the cell in which you intend to get the
value from.
` In this example we will get the value of a cell and display it in the
Status Bar. We get the cell value during the onDataLoad event because
the Data Grid cells do not have values until this event occurs.
var myGrid = new dax_dataGrid('People', null);
myGrid.showStatusBar(true);
myGrid.go();
myGrid.onDataLoad = function() {
var cellValue = myGrid.getCellValue (2, 3);
myGrid.showStatusMessage(cellValue);
}
myGrid.setCellValue(1, 2, myContents);
Sleep This command will cause the Data Grid to no longer automatically
communicate with 4D. Thus, periodic updates such as automatic data
refreshes and the refreshing of Data Driven Preset Queries will no
longer occur.
Note The user, however, still can manually interact with the Data Grid with
full functionality (except for automatic communication).
myGrid.sleep();
This command is useful when the Data Grid is hidden, and when
resources are not intended to be used to update it. Use .wake() to
resume automatic updates.
` This example puts the Data Grid to sleep and then hides it.
myGrid.sleep();
// hide grid
$('myGridDiv').style.visibility = 'hidden';
Wake This command will wake a Data Grid that was previously put to sleep.
It will resume all periodic updates (data refresh, unique query refresh)
that were paused with the .sleep() command.
myGrid.wake();
` This example sets a Data Grid that previously set to 'hidden' to be
'visible.' Then all periodic communication with 4D is resumed using
the .wake() command.
// show grid
$('myGridDiv').style.visibility = 'visible';
myGrid.wake();
Search and The Search Toolbar displays only the fields you specify as searchable in
advanced search the 4D Ajax Framework Client environment.
toolbar
Note To make a field searchable, in the Client go to Control Panel -> Access
Control tab. Select the table the field belongs to. For each field you
want searchable, check the 'S' checkbox.
To override these searchable fields with a new list, use the following
command.
myGrid.updateSearchFieldList(recordID);
recordId - String. Unique value defined for each record denoted by
two values x and y in the format '[x][y]'.
` This example enables the fields Last and City as searchable based on
their Record IDs:
myGrid.updateSearchFieldList([ '[1][2]', '[1][4]']);
` Remember, you can also use dax_getField and the attribute fieldid to
retrieve field IDs, as seen in this example:
myGrid.updateSearchFieldList([
myGrid.dax_getField("Employee","FirstName").fieldid,
myGrid.dax_getField("Employee","LastName").fieldid]);
Reference
Use the commands in this section to reference specific areas on the
Data Grid such as rows, columns, or cells.
Get Column number Use this command to get a column number using a Field ID. It is best
to use 4D Ajax Framework Bridge command dax_getField beforehand to
get the Field ID in the first place.
var columnNumber = myGrid.getColumnByFieldId(fieldId);
` Example
// find out which column belongs to field [Employee]FirstName
var fieldId = dax_getField('Employee', 'FirstName').fieldid;
var employeeFirstNameColumn = myGrid.getColumnByFieldId(fieldId);
Also see the example in section “Change header and footer row
height” on page 22.
Get cell pointer Use this command to get a cell reference based on its row and column
number.
var myCell = myGrid.getCell(row, column)
Cell Properties Here are the properties of a given cell. Use the getCell command to get
a reference to a cell and then use the properties listed below to get
more information on it.
` This example will get a reference to a cell. From there it will display the
cell's value in the Status Bar. We get the cell value during the
onDataLoad event because the Data Grid cells do not have values until
this event occurs.
var myGrid = new dax_dataGrid('People', null);
myGrid.showStatusBar(true);
myGrid.go();
myGrid.onDataLoad = function() {
// Get reference to cell in Row 3 and Column 4
var myCell = myGrid.getCell(3,4);
// Display cell's value in Status Bar
myGrid.showStatusMessage(myCell.value);
}
Get row pointer Use this command to get a reference to a row based on its row number.
Row numbering starts at 0 (zero).
var myRow = myGrid.getRow(row)
Row Properties Here are the properties of a given row. Use the .getRow command to get
a reference to a row and then use the properties listed below to get
more information on it.
` This example will get the reference for the 4th row and then display its
Record ID in the browser's Alert dialog. We get the row's Record ID
during the onDataLoad event because Record ID's are undefined before
this event occurs.
var myGrid = new dax_dataGrid('People', null);
myGrid.go();
myGrid.onDataLoad = function() {
// get reference for 4th row
var myRow = myGrid.getRow(3);
// show record id via .recordId property
alert ('Record id for this row is' + myRow.recordId);
}
Get column pointer Use this command to get a reference to a column based on its column
number. Column numbering starts at 0 (zero).
var myColumn = myGrid.getColumn(column)
Column properties Here are the properties of a given column. Use the .getColumn
command to get a reference to a column and then use the properties
listed below to get more information on it.
` This example will see if the 3rd column is visible and display its status
in the Status Bar.
var myGrid = new dax_dataGrid('People', null);
myGrid.showStatusBar(true);
myGrid.go();
Presentation
Change the complexion of Data Grid with the following commands.
Set row height in This will change the base row height in pixels for all rows - this
pixels includes all rows as well as all headers and footers. Row height in units
is preserved, so row with height of 2 units will have final height of (2 *
new size in pixels).
myGrid.setRowHeightInPx(rowHeight);
rowHeight - new row height in pixels
` This example will make the default row height to be 25 pixels. The
default row height will change for all rows, headers, and footers.
myGrid.setRowHeightInPx(25);
Change header and Use these commands to change the row height of the header or footer.
footer row height
Note These calls must be made immediately after .go():
` Here we will create a grid with 2 header rows and 1 footer row. We will
set some of these rows to the height of 2 units:
// Create Data Grid with 2 header rows
var myGrid = new dax_dataGrid('People', null, 2);
Note The Control Column is column 0 because it was set to true by default
when the Data Grid was created.
` This example will set the 3rd column from the left to a width of 150
pixels:
myGrid = new dax_dataGrid('People',null);
myGrid.go();
myGrid.setColumnWidth(2, 150);
To get column width in pixels:
var myColumnWidth = myGrid.getColumnWidth(colNum);
colNum - The number of the column starting from the left side of
the Data Grid. Numbering begins at 0 (zero) so the left-most
column is column 0 (zero).
` In this example will return the width of the 3rd column from the left:
var myColumnWidth = myGrid.getColumnWidth(2);
Allow user resizing This command allows or prohibits user resizing of columns with click
& drag interface:
myGrid.allowColumnResize(allowColumnResize);
allowColumnResize - Boolean. Set to True to allow column resizing.
Set to False otherwise.
Query
Query-related commands reside here.
New Query, Add Create a new query using the following command:
Query, and Run .newQuery();
Query
Then add and define the query conditions using the following
command:
.addQuery(field name, operator, value, and/or flag);
field name - String, name of the field to query.
Send custom values Send custom value names and pairs to the back end using the
to 4D following:
myGrid.addCustomValue(name, value);
name - String, name of the custom value.
` This is a block of code that would perform a query during the user click
of an input button.
JavaScript portion:
// clear all existing values
myGrid.clearCustomValues();
HTML portion:
My City: <input type="text" id="myCity" />
My State: <input type="text" id="myState" />
Get custom values Use this command to return information from 4D back to the browser:
from 4D myCustomValues = myGrid.getCustomValuesFrom4D();
Note A set of web variables are passed from 4D to the front end using the 4D
method Dax_Dev_SetCustomVariables. This method can pass variables
to the front end during the following Developer Hooks:
Dax_DevHook_OnQuery (non-DCS support only)
Dax_DevHook_QueryFilter (non-DCS support only)
Dax_DevHook_DCS_SetSelection (DCS support only)
Example:
ARRAY TEXT($varNames_at;3)
ARRAY TEXT($varValues_at;3)
$varNames_at{1}:="v1"
$varNames_at{2}:="v2"
$varNames_at{3}:="v3"
$varValues_at{1}:="aaa"
$varValues_at{2}:="bbb"
$varValues_at{3}:="ccc"
DAX_Dev_SetCustomVariables (->$varNames_at;->$varValues_at)
Important:
1. The size of the 2 arrays must be the same, otherwise, the size of the
value array will be adjust to the size of the name array.
2. If the method is called more than once, the one before the last
execution will be used.
On the front end side, the object received has the following properties:
myCustomValues.length -> number of returned values
Note This example can be further inspected in the Header and Footer example
of the Data Grid sample database,
Query all records Use this command to query all records in the Data Grid.
myGrid.queryAllRecords();
` This call will cause the Data Grid to display all records.
myGrid.queryAllRecords();
Max number of Use the command to set the maximum amount of characters 4D will
characters per field send per field.
myGrid.querySetMaxChar(number of characters);
number of characters - Integer, representing the max number of
characters 4D will send per field.
// Sort
myGrid.sort('First', 'asc');
On Before and On Here are two events that can be used before or after sorting occurs.
After Sort
Before sorting:
myGrid.onBeforeSort = function() { };
After sorting:
myGrid.onAfterSort = function() { };
Before data display This event occurs when data arrives from 4D, but it's not displayed yet.
This would be an ideal time to perform data manipulation before it
gets displayed on the Grid.
myGrid.onBeforeDataDisplay = function() { };
Here is a recommendation of commands to consider executing during
this event:
getParsedDataValue
setParsedDataValue
getCustomValuesFrom4D
` This example will get data back from 4D, and capitalize every true
value in the [Employee]IsManager field. This happens before data is
displayed inside onBeforeDataDisplay handler.
// declare Data Grid variable
var myGrid;
// get value
var value = this.getParsedDataValue(recordCount, columnNumber);
Get number of Use this command to get the number of records returned from 4D.
returned records myGrid.getParsedDataRecordCount();
` This example will get the number of records from 4D and display it in
an alert message. This number should match the number of records
displayed in the Status Bar.
myGrid = new dax_dataGrid('People');
// Show Status Bar to display number records
myGrid.showStatusBar(true);
myGrid.go();
Selection
Select row by record Highlight a row based on its Record ID.
id myGrid.selectRowByRecordId(recordId);
recordId - String. Unique value defined for each record denoted by
two values x and y in the format '[x][y]'.
Add, remove, and Use these commands to add, remove, or clear records to a selection.
clear
To add a record to a selection:
myGrid.addRecordToSelection(recordId);
recordId - String. Unique value defined for each record denoted by
two values x and y in the format '[x][y]'.
Selection Mode Defines how many rows can be selected at a time with a row click.
myGrid.setSelectionMode(selectionMode);
Note These values are case sensitive. Thus, they must be lower-case.
function daxLoginSuccess() {
// create first grid, this will be the target for drag & drop
action
gridOne = new dax_dataGrid ('Employee', $('gridOne'), 1, 0,
false);
gridOne.setSelectionMode('none');
// give custom CSS class to visually show if cell is selectable
gridOne.ondragover = onDragOverEvent;
gridOne.go();
CSS portion:
.dax_datagrid .dragdrop_style {
background-color: red;
}
HTML portion:
<div id="gridOne" style="width: 500px; height: 300px;"></div>
<div id="gridTwo" style="width: 500px; height: 150px;"></div>
Set cells as drop A Drop Zone is an area where an object can be drag and dropped into.
zone Use this command to set specific rows or columns as a drop zone.
myGrid.setDropCells(row, column, isDroppable)
row - Specify row to be set as a drop zone. Pass null for all rows to be
set as a drop zone. Numbering begins at 0 (zero) so the top-most
row (the header) is row 0 (zero).
column - Specify column to be set as a drop zone. Pass null for all
columns to be set as a drop zone. Numbering begins at 0 (zero) so
the left-most column is column 0 (zero).
isDroppable - Boolean. Enter True to set area as droppable. Enter
False otherwise.
Set cell as draggable Set cells, rows, or columns as draggable using this command.
myGrid.setDragCells(row, column, isDraggable);
row - Specify row to be set as a draggable. Pass null for all rows to be
set as a drop zone. Numbering begins at 0 (zero) so the top-most
row (the header) is row 0 (zero).
column - Specify column to be set as a draggable. Pass null for all
columns to be set as a drop zone. Numbering begins at 0 (zero) so
the left-most column is column 0 (zero).
isDraggable - Boolean. Enter True to set area as draggable. Enter
False otherwise.
Draggable cells will not support mouse hover and selection mechanics.
No cells are set as draggable by default.
During the drag & drop process, source cell is also accessible through:
dax_bridge.hoverDragging.dragObjectSource
Set draggable To make any object on the HTML page draggable, call this command.
object dax_setDraggable(draggableObject);
This will not move the actual object, but create a floating copy when
dragged.
Window
Status bar The Status Bar is the bar at the bottom of the Data Grid displaying
status information.
By default the Status Bar displays generic information such as the total
number of records or the amount of records currently selected.
myGrid.go();
Show message Use this command to display values in the Status Bar.
myGrid.showStatusMessage(message);
` In this example we will get the value of a cell and display it in the
Status Bar. We get the cell value during the onDataLoad event because
the Data Grid cells do not have values until this event occurs.
var myGrid = new dax_dataGrid('People', null);
myGrid.showStatusBar(true);
myGrid.go();
myGrid.onDataLoad = function() {
var cellValue = myGrid.getCellValue (2, 3);
myGrid.showStatusMessage(cellValue);
}
Toolbar The Toolbar is a bar above the Data Grid that features the following
capabilities:
Create a new record
Note The features are displayed on the Data Grid from left to right in the
order they are listed in the .showToolbar command.
Preset queries
Preset queries are queries created in the control panel via the Query
Manager tab. These queries can be represented as Sidebars or Tabs.
Sidebar The Sidebar is an area on the Data Grid displaying the Preset Queries a
list.
Note Field(s) used for Dynamic Queries must have at least one of the
visibility checkboxes turned on in the control panel.
Tabs Preset Queries can also appear as Tabs above the row and column area
of the Data Grid.
` This example will run a Preset Query named B which will display all
records in the Last name field which start with the letter B.
myGrid = new dax_dataGrid('People');
myGrid.go();
//
myGrid.runPresetQuery ('B');
Editor
The Editor is a sheet that appears that allows users to modify values or
add values for a new record in the Data Grid.
New record Use the new record command to display the Editor sheet for adding a
new record.
myGrid.editorNewRecord();
` This example displays the Editor sheet for a new record:
myGrid = new dax_dataGrid('People');
myGrid.go();
Edit record Use the following command to modify an existing record using the
Editor sheet, based on its record ID.
myGrid.editorEditRecord(recordId);
recordId - String. Unique value defined for each record denoted by
two values x and y in the format '[x][y]'.
` This example will display the Editor sheet for the record with ID [1][2]:
myGrid.editorEditRecord('[1][2]');
Allow editor This command disables or enables the record editor to appear when
users double click on a row. The record editor is enabled by default.
myDataGrid.allowEditor(boolean);
boolean - Set true to enable the record editor. Set false otherwise.
Inline editing
Typically, to modify records the user would double click on a record
and an Editor sheet would appear allowing them to edit field values.
Inline Editing, on the other hand, allows the user to modify or add
records in the Data Grid without having to do so in another sheet, but
in the Data Grid itself.
Boolean fields appear as check boxes. The values depend on the for-
matting rules selected in the Control Panel.
Callbacks: 4D Callbacks are supported during Inline Editing.
If no parameters are passed, inline edit will be blank and save a new
record.
Save edited record Use this command to programmatically save the current record that is
being edited through Inline Editing.
myGrid.inlineEditSave();
Cancel inline editing Use this command to programmatically clear the current record that is
being edited through Inline Editing.
myGrid.inlineEditClear();
Events
On cell, row, column To assign custom functions to the column, row, or cell click events,
click assign them to the respective grid functions.
Returning false will prevent default data grid actions (selection, for
example).
On data load This is the time when data populates the Data Grid. Note that many
other Data Grid commands are data dependent, so in many cases
onDataLoad would be the only appropriate time to use them.
myGrid.onDataLoad = function() { };
` In this example we will get the value of a cell and display it in the
Status Bar. We get the cell value during the onDataLoad event because
the Data Grid cells do not have values until this event occurs.
var myGrid = new dax_dataGrid('People', null);
myGrid.showStatusBar(true);
myGrid.go();
myGrid.onDataLoad = function() {
var cellValue = myGrid.getCellValue (2, 3);
myGrid.showStatusMessage(cellValue);
}
Before and After When the mouse hovers over a 'View Image' link for a picture field, a
Hover preview of that image appears. The following two events fire for this
action, onBeforeHover and onAfterHover. They are shown below.
This event fires when the mouse first hovers over the link.
myGrid.onBeforeHover = function() { };
This event fires when the mouse hovers away from the link.
myGrid.onAfterHover = function() { };
` In this example, a blank image in a separate <div> displays the image
that is previewed when it is being hovered over. When the mouse
leaves the link, the <div> becomes blank again.
This is the JavaScript code in onAfterInit:
myGrid = new dax_dataGrid('Contacts', $('mydiv'), 1, 0,
false);
myGrid.enablePicturePreview(true);
myGrid.go();
myGrid.allowEditor(false);
This is the HTML with the <div> containing the image element with
ID "mypreview".
<div style="float: right; width: 213px; margin-left: 35px;
margin-top: 35px;">
<img id="mypreview" src="blank.png" width="0" height="0"/>
</div>
CSS Styling
Change the look of the Data Grid's rows, columns, and cells using CSS.
There are two ways of approaching this:
Override the framework's existing styling
Override Styling To override the framework's CSS styling, it helps to know the following
CSS classes available based on data type:
.datanumeric - Numeric fields
.datatext - Text fields
.datatime - Time fields
.datadate - Date fields
.databoolean - Boolean fields
.dataheader - Headers
Note The point here is that the framework already has CSS styling defined
for .dax_datagrid. To override the existing styling, define CSS classes
prefixed with .dax_datagrid.
` To override the 'text-align' attributes for the Data Grid add this CSS
code:
<style type="text/css">
</style>
This code would override the text-align attributes for all numeric and
text fields in the grid.
Set entire grid class This command appends the class name to the grid. This means that
any style that starts with .myClassName can be applied for this specific
grid.
myGrid.setGridClass(className);
CSS portion:
<style type="text/css">
.style1 .datatext, .style1 .datanumeric {font-size: 11pt;
text-align:center; font-weight:bold;}
</style>
JavaScript portion:
myDataGrid.setGridClass('style1');
Like the previous example, this sample will make numeric and text
fields center aligned (as well as having bolder text and a modified font
size).
Assign classes to The following commands change CSS styling more dynamically (for
Rows, Columns, and example, on a user click).
Cells
Change CSS for a row:
myGrid.setRowStyle(row, styleName,
alternateRowStyleName, useAsDefault);
row - Integer, row number.
` This example will set CSS styling for row, column, and cell based on a
user click. Event onDataCellClick is used to catch the user clicks.
Buttons are also used to change grid class using .setGridClass()
myGrid.setSelectionMode('none');
//update values
lastSelectedRow = row;
lastSelectedColumn = column;
// set values
myGrid.setRowStyle(row, 'redColor');
myGrid.setColumnStyle(column, 'greenColor');
myGrid.setCellStyle(row, column, 'blueColor');
}
function button_changeGridStyle1() {
// check if grid exists. If it doesn't, skip the rest of the method
if (!myGrid)
return false;
function button_changeGridStyle2() {
// check if grid exists. If it doesn't, skip the rest of the method
if (!myGrid)
return false;
// The empty space here will equate to nothing, setting the Data
Grid's // CSS class to default settings.
myGrid.setGridClass(' ');
$('changeGridStyle1').onclick = button_changeGridStyle1;
$('changeGridStyle2').onclick = button_changeGridStyle2;
CSS code. Default Data Grid CSS class .dax_datagrid and CSS class
.inverseStyle are defined here:
<style type="text/css">
.dax_datagrid .redColor {
background-color: red;
}
.dax_datagrid .greenColor {
background-color: green;
}
.dax_datagrid .blueColor {
background-color: blue;
}
.inverseStyle .redColor {
background-color: purple;
}
.inverseStyle .greenColor {
background-color: yellow;
}
.inverseStyle .blueColor {
background-color: silver;
}
</style>
Code within <Body>. The buttons used to change the Data Grid's CSS
class as a whole are defined here:
<input class="myButton" type="button" id="changeGridStyle1"
value="Change style" />
Hitting the Restore Style button will then use .setGridClass() to restore
the CSS to it's default settings.