/// <reference path="~/GeneratedArtifacts/viewModel.js" />
/// <reference path="../Scripts/wijmo.cba.js" />

myapp.GridConditionalImages.FlexGrid_render = function (element, contentItem) {
    var grid = new c1.cba.FlexGrid($(element), contentItem);
    var collectionView = new c1.cba.LightSwitchCollectionView(contentItem);
    grid.wjControl.itemsSource = collectionView;
    grid.wjControl.itemFormatter = function (panel, r, c, cell) {

        // validate CellType and if correct column
        if (wijmo.grid.CellType.Cell == panel.cellType &&
          panel.columns[c].header == 'country') {
            // get the cell's data
            var cellData = panel.getCellData(r, c);
            var img = $("<img style='height:26px; width:48px'/>").attr("src", "Countries/" + cellData + ".jpg");

            // set cell's foreground color
            $(cell).empty().append(img);
        }
    };
};
