As mentioned in the section "Implementing" there
are several methods by which data can be supplied. There
are several considerations when choosing which method to
use but the main ones are,
- Is the Data Static or Dynamic
- Where is your data held (eg. Database)
- Future maintainability
The supported methods for supplying data are,
In addition to raw data it is also possible to add the
following features to any grid cell,
Adding a URL Hyperlink - click here
Adding an Icon Image - click here
a)
via a Plain Text Data File.
Under this method The applet will read all the cell data
from a specified file. The data can be in one of 2 formats,
- Character
(comma) Separated or
- Fixed
Width
In both cases each row of data is supplied on each line
of the text file.
Character Separated
This is the most common format and generally a comma character
is used to separate the columns of data on each row. By
default the Data Grid will assume the data is separated
by a comma and so if your data is in this format then
simply add the following parameter,
<PARAM
name="griddata" value="griddata.txt">
replacing "griddata.txt" with the URL to your
data file.
If your data is separated by a character other than a
comma (eg. a hash # character) then you can override the
default setting with the following parameter,
<PARAM
name="dataseperator" value="#">
The
character separated method is used in Example 2 - click
here to view.
Fixed Width
Data may also be supplied in Fixed Width format. Here
is column of data resides at certain specified character
positions within each row. For example if you have 4 columns
of data then data may reside in the following positions,
- Column 1 - positions 1 to 19 - (19 characters)
- Column 2 - positions 20 to 29 - (10 characters)
- Column3 - positions 30 to 59 - (30 characters)
- Column 4 - positions 60 to 64 - (5 characters)
When supplying data from a file the Grid Control will
assume the data is character separated, however this can
be overridden with the "datafiletype" parameter.
To specify Fixed Width format the following parameter
should be added,
<PARAM
name="datafiletype" value="1">
In addition the column widths need to be defined. This
is done with the "fixedwidths" parameter. Here
the number of characters for column are simply stated
separated by a "|" character. For the example
above we would need,
<PARAM
name="fixedwidths" value="19|10|30|5">
^back to top
b) via a Server Side Script (Database Connectivity)
This
option is the most powerful and gives the applet the ability
to retrieve data from databases without compromising database
security. This method involves specifying a server side
script in the html page which in turn returns the data to
the Grid applet, giving enormous flexibility for data acquisition.
Why
can't the applet just connect directly to a database ?
We have deliberately made it so that the applet cannot
connect directly to a database for security reasons. In
order for the applet to connect directly to a database
it would be necessary to supply the following information,
- URL
to the Database
- Database
Username
- Database
Password
Because the applet resides in your web page it would
be possible for anyone capable of viewing your web page
to also (with a little effort) obtain the above information.
In the hands of the wrong person this would be a disaster.
Hence we insist that database access is achieved via a
separate Server Side Script where it is note possible
for a malicious third party to obtain your database access
information.
The
server side script can be constructed in the language of
your choice (eg. ASP, JSP, Java Servlet etc.) and as such
can be written to acquire data from the widest variety of
sources, multiple databases etc.
The
server side script should be designed to produce output
in the format described for the supplying data via a plain
text file. Note: The script does not need to produce a physical
file it just needs to return the data in this format.
As with
supplying data via a file, you can choose this format to
be either,
To instruct
the applet to retrieve data from a server side script simply
insert the following <PARAM> tag between the <APPLET>
and </APPLET> tags in your html page.
<PARAM
name="griddata" value="[URL of Server Process]">
inserting
the URL of your server side application in the value element
of this tag.
For
an example script see GridDataServlet.java
in the ServerTemplateScripts directory. This is a simple
Java Servlet but equally the same method can be employed
in any scripting language,
ie.
Upon request,
- Connect
to Database
- Read
the Database records
- Process
and Format the data
- Return
the Data
This
method is used in Example 3 - click
here to view.
^back to top
c) From within the HTML page via PARAM tags
This
option is the simplest method of supplying data to the grid
applet and is probably most useful where the grid data is
either static or the html page is constructed dynamically,
(e.g.. Via ASP or JSP.)
Under this method each row of data is supplied by a "dataN"
parameter where N represents the row number. The row numbering
should begin with 1 and be continuous.
When supplying data via the HTML param tags the data must
be in "Comma Separated" format.
For an example set of Data Parameters see the file dataparamtags.txt
(click here).
This
method is used in Example 1 - click
here to view.
Any Cell in the grid can have a hyperlink URL attached to
it. This is done by adding the following to the data string,
for example to have the cell which contains the data "cell
1 data" link to Jpowered and display the result in the
current browser window, the data would be,
Any Cell in the grid may have an icon image attached to it.
This is done by simply adding the following to the data string,
For example to the image "cellimage1.gif" displayed
in the cell for the data "cell 1 data" you would
have,