Translations of this page:

Die datatable ist die Klasse für eine „normale“ nicht editierbare Tabelle. Sie kann ihr übergebenen Daten auf vielfältige Art & Weise darstellen.

Die datatable ist eine Subklasse von app und Überklasse von edit_table.

datatable(target, cols, colTitles, colWidths) [Konstruktor]

Insanziert die datatable

  • target: ein DOM-Elemnt, oder id eines DOM-Elementes, in welches die Tabelle gezeichnet werden soll
  • cols: numerisches Array der anzuzeigenden Spalten, bestimmt die Spaltenreihenfolge
  • colTitles: optional, Hashtable, Schlüssel : Spaltenname, Wert: deren Beschriftung
  • colWidths: optional, Hashtable, Schlüssel : Spaltenname, Wert: Breite in Pixeln

drawTable(data, pos, sortedCol, sortDir)

Übergibt der Tabelle die anzuzeigenden Daten. Die Tabelle zeichnet sich nach diesem Aufruf neu.

  • data: Numerisches Array der anzuzeigenden Datensätze
  • pos: optional, Setzt die Startposition, macht eigentlich nur Sinn im Zusamenhang mit Cachtabellen
  • sortedCol: optional, eine der angezeigten Spalten. Diese bekommt dann eine spezielle CSS-Klasse so dass ein kleines Pfeilchen angezeigt wird das angibt dass die Daten nach dieser Spalte sortiert sind.
  • sortDir: optional, in welche Richtung sortiert ist („ASC“ oder „DESC“), um den Pfeil auch richtig darzustellen.

ACHTUNG: Die Tabelle sortiert die Daten nicht selbst, Sie müssen dafür sorgen dass die Daten auch nach der Spalte sortiert vorliegen die Sie sortedCol angeben

Javdoc-styled Dokumentation der Methoden

Überblick

/**
*	- public datatable(HTML_Element container, NumericArray cols [, Hashtable colTitles, Hashtable colWidth]); [Constructor]
*
*	- public void drawTable(NumericArray data [, int pos, String sortCol, String sortDir]);
*	- public void setColTitles(Hashtable colTitles);
*	- public void setColWidth(Hashtable colWidths);
*	- public void setColumns(NumericArray cols [, Hashtable colTitles, Hashtable colWidhts]);
*	- public void setColumnFormat(String colName, String attributes);
*	- public void setRowFormat(Hashtable attributes);
*	- public void setAlternation(NumericArray attributes);
*
*	- public void setTableName(String tableName)
*	- public void setRenderer(String col, Object renderer);
*	- public void setRowNumCol(boolean rowNumCol);
*	- public void setHeader(booelan header)
*	- public void setIdCol(String IdColName);
*	- public String getIdCol();
*	- public int setSelectionMode(String selectionMode);
*	- public int countSelectedRows();
*	- public NumericArray getSelectedRows();
*	- public NumericArray getSelectedIds();
*
*	- public void getSelectedCellRowIndex();
*	- public void getSelectedCellColIndex();
*
*	- public void setStartPos(int startPos);
*	- public void addRows(NumericArray data, String where);
*	- public void removeRows(int from, int until);
*	- public void setData(absPos, data);
*	- public void setRowId(int absPos, String id);
*	- public String getRowId(int absPos);
*	- public int getRowHeight();
*	- public int getHeaderHeight(int absPos);
*	
*	- protected void drawHeader(String sortCol, String sortDir);
*	- protected void drawBody(NumericArray data);
*	- protected String buildRow(int relPos, Hashtable record);
*	- protected void addRowsToDom(NumericArray data, String where);
*	- protected String translateValue(String col, Hashtable record);
*	- protected void updateSelection(int absPos, Event event);
*
*	- private void clicked(HTML_Element element, Event event);
*/

public interface datatable {

PART I

Functions to use the datatable to show some data (e.g. a result of an SQL-Query)

	/**
	*	Constructor.
	*	Instantiates the datatable
	*	@param container: the container to place it into
	*	@param cols: array of the columns of the table
	*	@param colTitles the titles for the columns, keys are the column-names (param cols)
	*	@param colWidth the width of the columns, keys are the column-names (param cols)
	*/
	public datatable(HTML_Element container, NumericArray cols [, Hashtable colTitles, Hashtable colWidth]);
	

	/**
	*	draws the table using the given data
	*	@param data: the 2D- array of data to be shown keys in the 2nd dimension shoud correspond to the tablenames
	*	@param pos: the position of the first record in the data array, used to get absolute row positions
	*	@param sortCol: the column the table is sorted (just used to indicate this in the header)
	*	@param sortDir: the direction the table is sorted "ASC" or "DESC" (just used to indicate this in the header)
	*
	*
	*	@over-wirtten by: edit_table!
	*/
	public void drawTable(NumericArray data [, int pos, String sortCol, String sortDir]);

	
	/**
	*	Sets the column titles shown in the header (otherwise the column-names will be shown in the header)
	*	@param colTitles, the column titles, keys must be the column names
	*/	
	public void setColTitles(Hashtable colTitles);


	/**
	*	Sets the column widths, otherwise a default width is used for each column
	*	@param colWidths, the column widths, keys must be the column names
	*/	
	public void setColWidth(Hashtable colWidths);


	/**
	*	Sets the columns to be shown, empties the table! call drawTable or addRows afterwards!
	*	@param cols, array of the columns of the table
	*	@param colTitles, the column titles, keys must be the column names
	*	@param colWidths, the column widths, keys must be the column names
	*/	
	public void setColumns(NumericArray cols [, Hashtable colTitles, Hashtable colWidhts]);


	/**
	*	Sets attributs for each cell of the specified column, incl. the head-Cell of this column
	*	@param colName, the column to set the attributes for
	*	@param attributes, the attributes for the cells, (e.g. "align='right' color='red'") 
	*/	
	public void setColumnFormat(String colName, String attributes);


	/**
	*	Sets attributs for each row, the attribute-values will be templated
	*	@param attributes, the attributes for the table-rows, (e.g. {"style":"background-color:{color}"} ) 
	*/	
	public void setRowFormat(Hashtable attributes);


	/**
	*	Sets attributes which debend from the row-position (used to get an alternation)
	*	@param attributes, an array of attribute-Hashtables, 
	*		the length oif the array defines all how many rows the same attributes are used
	*		it is usually 2 to get a simple alternation.
	*		e.g. [{'style':'background-color: #ffffdd;'}, {'style':'background-color: transparent;'}]
	*/	
	public void setAlternation(NumericArray attributes);


	/**
	*	Sets the tables name, the name will be passed as third argument
	*	if the table calls the translateValue mehtod of a renderer.
	*	@param tableName : the name for the table
	*
	*/
	public void setTableName(String tableName);
	
	/**
	*	Sets a specific renderer for the Values of a column
	*	teh renderer mus offer a function 
	*		- translateValue(String colName, Hashtable record, String tableName)
	*		which returns the HTML-Code for the this cell as String
	*
	*	@param col, the column this renderer is used for
	*	@param renderer the renderer-object 
	*/	
	public void setRenderer(String col, Object renderer);


	/**
	*	Defines whether a RowNumberColumn will be shown as most left Column or not.
	*	@param rowNumCol, true or false
	*/	
	public void setRowNumCol(boolean rowNumCol);

	/**
	*	Sets if the tableheader should be visible, default is true
	*	@param header, true or false
	*/
	
	public void setHeader(boolean header);

	/**
	*	If the values of one column should be used as identifier for the 
	*		selection and/or editing mechanism. (this coulumn need's not to be shown or be part
	*		of the colNames-Array, but it has to be in the data Arrays given via drawTable, 
	*		addRows or setData!) 
	*		
	*	@param IdColName, the name of the identifier Column (typically "id" or "ahv_nummer");
	*/	
	public void setIdCol(String IdColName);
	
	
	/**
	*	Returns the column that is used as identifier column
	*	@return the colName
	*/	
	public String getIdCol();
	
	
	/**
	*	Sets the selection-mode for the table
	*	3 possibilities : no-selection, single-rowselection (only one row may be selected at one time) 
	*		or muliple-selection.
	*		The 3 Constants SEL_MODE_NONE, SEL_MODE_SINGLE, SEL_MODE_MULTIPLE should be used!
	*	@param selectionMode, the desired selection-mode
	*/	
	public int setSelectionMode(String selectionMode);
	
	
	/**
	*	Counts the number of selected rows
	*	@return how many rows are selectoed
	*/	
	public int countSelectedRows();
	
	
	/**
	*	Returns the selected rows
	*	@return a numeric array containing the absolute positions of all selected rows
	*/	
	public NumericArray getSelectedRows();
	
	
	/**
	*	Returns the ids of the selected rows
	*	@return a numeric array containing values of the id-Col of the selected rows
	*/	
	public NumericArray getSelectedIds();
	
	/**
	*	Returns the rowindex (absolute) of the selected Cell (cursor)
	*	@return the rowindex
	*/	
	public int getSelectedCellRowIndex()
	
	/**
	*	Returns the column-index of the selected Cell (cursor)
	*	@return the column
	*/	
	public int getSelectedCellColIndex()

PART II

Functions especially the cachetable uses.

	/**
	*	Sets the start-Position (i.e. the absolute position of the actually shown row 0)
	*	Used to calculate an absolute position of each row.
	*
	*	@param startPos, the new start-Position
	*/
	public void setStartPos(int startPos);
	
	
	/**
	*	Adds as many rows to the table as contained into the data-Array, They could be
	*	added before the first or after the last row actually shown.
	*
	*	@param data, Numeric array of data, contains Hashtables for each record
	*	@param where, "beforeend" or "afterbegin"
	*/
	public void addRows(NumericArray data, String where);
	
	
	/**
	*	Removes rows from the given position until the given positions.
	*	These positions are looked as relative Positions, i.e. the indizes of the shown rows
	*
	*	@param from, First row to be removed
	*	@param until, Last Row, this row will stay in the table! (removeRows(0,1) removes 1 row, namely the first!)
	*/
	public void removeRows(int from, int until);
	
	
	/**
	*	Fills existing rows with data starts at a given absolute position
	*	absolutePosition is always: rowIndex + startPosition!
	*	Fills as many rows as records are contained in the data array
	*
	*	@param absPos, the absolute position of the first row filled with the given data
	*	@param data, Numeric array of data, contains Hashtables for each record
	*/
	public void setData(absPos, data);
	
	
	/**
	*	Sets the rowId vor a the specified Row
	*	@param absPos, the absolute position of the row
	*	@param id, the id to be set
	*/
	public void setRowId(int absPos, String id);
	
	
	/**
	*	Gets the rowId of a specified row
	*	@param absPos, the absolute position of the row
	*
	*	@return the id of this row, may be undefined if not set yet!
	*/
	public String getRowId(int absPos);
	
	
	/**
	*	Calculates the height of one row
	*	@return the row-height in pixel
	*/
	public int getRowHeight();
	
	
	/**
	*	Calculates the height of the header
	*	@return the header-height in pixel
	*/
	public int getHeaderHeight(int absPos);

PART IIIa

Protected functions used by the edit_table

	
	/**
	*	Draws the Header annd applies the defined colWidths to the table
	*	@param sortCol: the col (colName) which is sorted, just to indicate this, 
	*		the shown data-array must be sorted by the user of the table
	*	@param sortDir: the direction of teh sorting, ASC or DESC, just to indicate
	*/
	protected void drawHeader(String sortCol, String sortDir);
	
	
	/**
	*	Draws the Body of the table
	*	@param data: the data-array to be drawn, a numeric array of Hashtables (the records)
	*/
	protected void drawBody(NumericArray data);
	
	
	/**
	*	Creates the HTML-Code for one single row, and sets the rowId of this row if
	*		an id-Coulumn is defined (setIdCol). 
	*
	*	@param relPos the position of the row in the shown table (absolute position - start position)
	*	@param record the record of this row. 
	*
	*	@return the HTML-Code for this row as String. Without the <tr> tag, just the content!
	*/
	protected String buildRow(int relPos, Hashtable record);
	

	/**
	*	Adds as many rows to the table as contained into the data-Array, They could be
	*	added before the first or after the last row actually shown.
	*	Actually does the same like addRows, addRows just calls this function
	*	Exists to be able to overwrite addRows, and calling this function from the
	*	overriden addRows function.
	*
	*	@param data, Numeric array of data, contains Hashtables for each record
	*	@param where, "beforeend" or "afterbegin"
	*/
	protected void addRowsToDom(NumericArray data, String where);
	

	/**
	*	Called to get the value to be shown in a specific cell.
	*		- Returns usually by default record[col]
	*		- Calls "translateValue" of the renderer cor this col if one is set.
	*
	*	@param col, The colname of this cell
	*	@param record, the record of this row
	*
	*	@return the HTML-Code put into this cell
	*/
	protected String translateValue(String col, Hashtable record);
	

	/**
	*	Updates the selection of the table after a mousclick
	*
	*	@param absPos, the absolute position of the row clicked on
	*	@param event, the click event, needet to determine if
	*		Shift or Ctrl-Button is pushed.
	*/
	protected void updateSelection(int absPos, Event event);

PART IIIb

Functions over-written by the edit_table


	/**
	*	Called whenever a click od double-click somewhere on the
	*	Table is detected (also if the click is on the header or
	*	the rownumber Column).
	*
	*	@param element, the Element the click is detected on
	*	@param event, the click event
	*/
	private void clicked(HTML_Element element, Event event);
}

 
dev/datatable.txt · Zuletzt geändert: 26.07.2007 11:48 von kaegi
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki