:: Home >>

cell text

Sets or retrieves the text in the grid cells. The text is assigned to the individual cell or to the array of cells depending on the type and the number of arguments in the setCellText() method (see the examples below).

Does not encode the html controls characters (<, >, ", &) - the text containing correct html markup will be displayed as html.

This is a faster method than using cell data property because the text is inserted into the grid cells as is without any transformations. However using the cell data property together with the cell format converter allows processing the data before display, for example, encoding the text strings or applying specific date or number formats.

When the cell content is assigned through the cell text property - the cell format converter can be used to provide reverse transformation (textToValue) for the correct sorting of the grid rows.

During the editing the cell text property is continuously updated (on each keystroke, copy/paste or drag-n-drop event). Each text change triggers onCellTextChanging and onCellTextChanged events which can be used to check or modify the entered text.

Syntax

var value = obj.getCellText(); 
obj.setCellText(value);        

obj.onCellTextChanging = function(value){...}; 
obj.onCellTextChanged = function(value){...}; 
obj.onCellTextError = function(value){...}; 

Defined in

cell model

Examples

2-d Array

var myCells = [
    ["Cell <i>text</i>", "123", "5/18/2004"],
    ["<a href='#'>More...</a>", "456", "1/12/2006"]
]

obj.setCellText(myCells); // assign cells content

1-d array (per row)

obj.setCellText(["Cell <i>text</i>", "123", "5/18/2004"], 0); // row-0
obj.setCellText(["<a href='#'>More...</a>", "456", "1/12/2006"], 1); // row-1

Function

obj.setCellText(function(col, row){return myCells[row][col]});

Single cell

obj.setCellText("Item <1>", 0, 0); // col-0, row-0

Remarks

onCellTextChanging event can be used to restrict the cell text (filter characters) during editing -

obj.onCellTextChanging = function(text, column, row){
    if (text.match(/[^0-9.+-]/)){
        return "error"; // prevent non-digits
    }
}

See also

Grid templates: cell
Cell model: image, tooltip, link, value, data, format, editable, state, selected
Text properties: selector, header, footer, top, bottom

Comments

21 Aug 06
setCellText method used can cause setCellText by col to FAIL G. Cayman (8)
14 Aug 06
How to put a button in each cell of a column? Manuel Arroz (0)

Comments will appear on this page and in the main forum.

Documentation:

Recent changes:

2.6.4
2.6.3
2.6.2
2.6.1
2.6.1
2.6.0
2.5.0 - 2.5.6
2.5.6
2.5.0 - 2.5.5
2.5.5