:: Documentation >>

Adding cell 'indicator' element

This example shows how to modify the standard cell template - adding 'indicator' element, similar to Excel cell comments indicator (red triangle in the right top corner).

The code creates new cell template class.

// new cell template class
var MyTemplate = AW.Templates.Text.subclass();

MyTemplate.create = function(){

    var obj = this.prototype;

    // hides/shows indicator depending on cell/indicator poperty
    obj.setClass("indicator", function(){
        return this.getControlProperty("indicator") ? "visible" : "hidden";
    });

    // indicator span element
    var indicator = new AW.HTML.SPAN;
    indicator.setClass("item", "indicator");
    indicator.setEvent("onclick", function(){
        this.raiseEvent("onCellIndicatorClicked");
    });
    obj.setContent("box/indicator", indicator);
}

And also defines the CSS rules for the indicator.

.aw-item-indicator {
    display: none; /* hidden by default */
    position: absolute;
    overflow: hidden;
    right: 2px;
    top: 2px;
    width: 8px;
    height: 8px;
    background: red;
    cursor: pointer;
}

.aw-indicator-visible .aw-item-indicator {
    display: block; /* visible */
}

In the grid control it is necessary to add new cell/indicator property and assign our cell template.

// new cell property hides/shows indicator sign
obj.defineCellProperty("indicator", false);

// show for cell 1-1
obj.setCellIndicator(true, 1, 1);

// our new template for col-1
obj.setCellTemplate(new MyTemplate, 1);

obj.onCellIndicatorClicked = function(event, col, row){
    alert("Cell indicator - " + col + " " + row);
};

You may change the indicator background to the triangle (or other) image to make it look exactly like Excel feature.

See the complete code in the example below.

Comments

Single row selection and editable grid user1 (2)
multiply cell indicators Colin (4)
Suggestion for feature - cell marker Will (4)
Problems to obtain clientX and clientY on the cell ‘indicator’ chunk of code Raul (5)
odd behavior Raul (2)

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