Initialization and Read-Only Mode

SpreadSheet can be initialized in 2 ways:

And can be used in 2 modes (regardless of the type of initialization):

Please note, before initializing you must adjust SpreadSheet Configuration.

Basic initialization

To perform basic initialization of SpreadSheet, you should make the only action - include the related file on the page:

<script src="../codebase/spreadsheet.php"></script>

At this point, if you run the page, Spreadsheet will be initialized in the fullscreen mode.

Available parameters:

  • icons_path - (url) the path to a folder containing SpreadSheet icons.
  • key - (string) the key of a SpreadSheet instance. It can be useful to protect your data from editing.
  • load - (url) the path to a file that will 'load' data (usually the default connector file is "codebase/php/data.php").
  • math - (boolean) enables formulas. "false" by default.
  • parent - (string) an HTML container for a SpreadSheet instance. If the parameter is not specified or set to null, SpreadSheet will be initialized in the fullscreen mode.
  • save - (url) the path to a file that will 'get' change requests (usually the default connector file is "codebase/php/data.php").
  • sheet - (string or number) the name of a Spreadsheet instance to load (if it doesn't exist, it will be automatically created).
  • skin - ("dhx_skyblue" or "dhx_web") sets the skin for a Spreadsheet instance. The "dhx_skyblue" skin is set by default.
<script src="../codebase/spreadsheet.php?sheet=2&key=key2&parent=box"></script>
<div id="box" style="width: 800px; height: 400px; background-color:white;"></div>

Advanced initialization

The following instructions describe how to perform advanced initialization of Spreadsheet:

Step 1. Include the related files.

<script src="codebase/spreadsheet.php?load=js"></script>
<link rel="stylesheet" href="codebase/dhtmlx_core.css">
<link rel="stylesheet" href="codebase/dhtmlxspreadsheet.css">
<link rel="stylesheet" href="codebase/dhtmlxgrid_wp.css">

Step 2. Create a dhtmlxSpreadSheet instance.

dhx_sh = new dhtmlxSpreadSheet({
    load: "../codebase/php/data.php",
    save: "../codebase/php/data.php",
    parent: "gridobj",
    icons_path: "../codebase/imgs/icons/"
});

Available parameters are the same as in case of basic initialization except for the 'key' parameter. It's specified in the load() method.

Step 3. Load Spreadsheet.

dhx_sh.load(sheet, key);

where:

  • sheet - the name of a Spreadsheet instance to load (if it doesn't exist, it will be automatically created).
  • key - the key of a Spreadsheet instance that defines the password level (optional).

Read-only mode

To activate the read-only mode, you should specify some key for a sheet in the database. Where to find this key?

During the configuration, Spreadsheet automatically creates several tables in the specified database, one of the tables is called 'sheet'. If you open this table, you'll find out that it contains 5 columns, one of which is the key column. So, to specify the key for a sheet, you should set some value in this column.

From now on, users will be able to modify data only if the key specified in the database and the key, specified in the key parameter during the initialization, match. In all other cases the read-only mode is activated (it will be activated even if you don't specify the key parameter at all).

Useful tips

Which initialization variant to prefer?

Surely the basic way is easier than the advanced one, but it has one imperfection which consists in the usage of the load and save parameters: you can't set compound URLs for them. For example, your load a file which is placed at http://someurl/data.php?test=1.

In the script it will look like this:

<script src="./codebase/spreadsheet.php?sheet=1&load=someurl/data.php?test=1"></script>

As a result, your browser will be confused by this text. How should it understand test? Is it the parameter of the load() function or an individual parameter passed to URL? Therefore, to prevent such a problem you must use the advanced way.

IE troubleshooting

In order to present the styles in Internet Explorer correctly, you must specify DOCTYPE of the document for your page.

<!DOCTYPE html>
Back to top