Tips
From Daxipedia
[edit] Date format for Data Window Live Search
The Live Search feature of the Data Window expects the date format YYYY-MM-DD or YY-MM-DD. A partial search, e.g. for "04" will search for the year 2004, by default.
[edit] Upgrading from v1.0 to v1.1 of the 4D Ajax Framework
There are three things you’ll need to do:
- Update 4D Ajax Framework component:
- Open your database using 4D Insider (4D version 2004.5 or later).
- From the Components menu, select “Install/Update…”
- Locate and open 4D Ajax Framework 1.1.4CP.
- The first prompt is to confirm your update, click “OK”.
- If you have made changes to one of the DAX_DevHook methods, you will be prompted again. Click “No All” if you wish to keep your current Developer Hook intact. Otherwise click “Yes” or “Yes All”.
- Quit 4D Insider.
- Update 4D Ajax Framework Library and Client:
- Open the DAX folder inside the 4D Ajax Framework 1.1 folder.
- Select and copy all files and folders to the clipboard.
- Open your database web folder and paste the files and folders from the clipboard into that folder.
- Open the Extras folder inside the 4D Ajax Framework 1.1 folder.
- Open the Support folder.
- Select and copy all files and folders to the clipboard.
- Open your database’s Extras folder.
- Open the Support folder and paste the files and folders from the clipboard into that folder.
- Activate your update:
- Open your database with 4D.
- You will be prompted to update the structure XML files. Click “Yes”.
[edit] Using the uncompressed framework files in v1.1
Starting with version 1.1 the 4D Ajax Framework uses compressed JavaScript and CSS files. If you would like to use the uncompressed versions of these files:
- Open the index.html in a text editor (or localized index file)
- Change the JavaScript include lines from:
<script language="javascript" type="text/javascript" charset="utf-8" src="dax/js/localization/resources_en.js"></script> <script language="javascript" type="text/javascript" charset="ISO-8859-1" src="dax/js/compile.js"></script>
To:
<script language="javascript" type="text/javascript" charset="ISO-8859-1" src="dax/js/framework.js"></script> <script language="javascript" type="text/javascript" charset="ISO-8859-1" src="dax/js/dax.js"></script>
- Change each of the stylesheet include lines to remove '_gz' from the name of the stylesheet.
From:
<link rel="stylesheet" charset="ISO-8859-1" href="dax/themes/basic/basic_gz.css" media="all" type="text/css" title="XPress" />
To:
<link rel="stylesheet" charset="ISO-8859-1" href="dax/themes/basic/basic.css" media="all" type="text/css" title="XPress" />
[edit] Embedding a grid into an HTML page
There was a question asked on the iNug about what it would take to go from a standard HTML page to a 4DAF live page with live grid capability, header sorting, live scrolling, and search capability. Here is some sample code to show the difference.
In a flat HTML page, you need code that displays the header and then calls and displays the data output. For example:
<table style="border: solid 1px #000;" cellspacing="0" cellpadding="0"> <tr> <th>First Name</th> <th>Last Name</th> <th>Email Address</th> <th>Phone</th> </tr> <!--#4dloop [People]--> <tr> <td><!--#4dvar [People]First_Name--></td> <td><!--#4dvar [People]Last_Name--></td> <td><!--#4dvar [People]Email_Address--></td> <td><!--#4dvar [People]Phone--></td> </tr> <!--#4dendloop--> </table>
To change that into a live Ajax grid using the 4D Ajax Framework, you would need to add small code snippets to the head and body of the page:
1) Call the 4DAF login script and initialize the grid. These would be done in the <head> section of the HTML page with a few lines of Javascript:
<script language="javascript" type="text/javascript">
// First we need to log in
function dax_load() {
Login("administrator", ""); // use 4D vars here for better security
}
// This is called after login and adds the grid
function onAfterInit() {
var myDataWindow = new DataWindow("People", null, null, null, null, false);
// var myDataWindow = new DataWindow("People", document.getElementById('newhotness'), null, null, null, false);
}
</script>
2) Call the code and specify where on the page it goes with these two snippets:
<body onload="dax_load()"> <div id="newhotness"></div>
Save your HTML, upload, and you’re good to go with an Ajax-enabled live data table.
[edit] Data Tree Break Levels
When creating data tree selections with views and multiple tables, make sure that the last break level belongs to the second to last table. For example, with Clients, Invoices and Invoice Line tables, you can define the first break level in Client and you would need to define the last break level in Invoices. If the last break level is in Client, new created record in Invoice Line would be orphan since that there is no Invoices record selected between the Client record and that new Invoice Line record.
[edit] Integrating the 4D Ajax Framework and Active4D
In 4D in the method 'On Web Connection', add a check for '/DAX/@' requests.
`On Web Connection
C_TEXT($1;$2;$3;$4;$5;$6)
If ($1="/DAX/@")
DAX_Dev_OnWebConn ($1;$2;$3;$4;$5;$6)
Else
` Do Any Active4D specific tasks here
End If
This will allow for both 4D Ajax Framework and Active4D requests to be processed correctly.
[edit] How to create a Callback method for On Data Change
In your method, you can retrieve the required parameter by using the example listed below.
DAX_Dev_GetCallBackVar ("table name";->$dax_TableName_t)
DAX_Dev_GetCallBackVar ("field name";->$dax_FieldName_t)
DAX_Dev_GetCallBackVar ("event id";->$dax_EventID_l)
DAX_Dev_GetCallBackVar ("table id";->$dax_TableID_l)
DAX_Dev_GetCallBackVar ("field id";->$dax_FieldID_l)
DAX_Dev_GetCallBackVar ("record id";->$dax_RecordID_l)
DAX_Dev_GetCallBackVar ("field value";->$dax_FieldValue_t)
DAX_Dev_GetCallBackVar ("message";->$dax_Message_t)
where
$dax_TableName_t, $dax_FieldName_t, $dax_FieldValue_t and $dax_Message_t are text variables $dax_EventID_l, $dax_TableID_l, $dax_FieldID_l and $dax_RecordID_l are long integer variables.
Based on those values, you can execute what your method needs to perform. If you want to return a message, you can assign your message to the $message_t variable and execute the following code:
DAX_Dev_SetCallBackVar ("message";->$message_t)
If your message is an error message, you might want to reject the tab and bring back the cursor into the current field. In that case execute the following code:
DAX_Dev_SetCallBackExeStatus (0)
Otherwise, if your code did not detect any error, execute the following code:
DAX_Dev_SetCallBackExeStatus (1)
You can now return the new value to the browser by assigning it to the $0 text variable.
Here is the format that needs to be applied for the defined types.
- Alpha and text: plain text
Ex: $0:=Uppercase($dax_FieldValue_t)
- Long integer, Integer and Real: numerical value in a string
Ex: $0:=String($vlongint_MyNewValue)
- Boolean: The strings "TRUE" or "FALSE"
Ex: $0:="TRUE"
- Date: YYYY-MM-DD in string format
Ex: $0:=String(Year of($fieldValue_d))+"-"+String(Month of($fieldValue_d))+"-"+String(Day of($fieldValue_d))
- Time: Time string
Ex: $0:=Time string($fieldValue_h)
Callbacks are not supported for other field types.
